tags:

views:

106

answers:

3

PHP allows me to:

Hello, my name is <?php echo $name ?>, and stuff.

Is that okay to do instead of

Hello, my name is <?php echo $name; ?>, and stuff.

I know the <?= ?> is being taken away, is this another one of those shortcuts to be killed?

A: 

I wouldn't count on it being legal, since something like this is legal:

<?php
    if($do_display) {
?>
    <div id="display">
    </div>
<?php
    }
?>

IMO, that's a horrible way to design pages, but...since that's legal, it would lead me to believe that parser state is kept between blocks, so your shortcut might only work for one block. That's an untested gut shot, but an educated one. (If it works now, it might not soon, we see what's happening with <?= ?>.) Might as well just drop the semicolon in and get it overwith.

Jed Smith
+11  A: 

It's technically okay, but most people will recommend against it. It's a "best practices" issue. If you get in the habit of leaving off the semicolon in single lines of code like that, it's more likely that you'll forget to do it in larger sections of code where it is required.

Jason
Good to know, thank you.
rpflo
A: 

It's not so much a shortcut as it is a bad habit which the interpreter doesn't do enough to discourage.

Azeem.Butt