by klausa · 14y ago · 0 comments
Also,
Chained string offsets - e.g. $a[0][0] where $a is a string - now work.
I have no idea how is that supposed to work. What should be the outcome on, say: $a = "foo"; $a[0][0]
What about (assuming $a is still "foo"): $a[0][1]
etc.?<?=$username;?>
(Personal Preference Alert!) Is easier to read, faster to type and easier for designers to handle than:
<?php echo $username;?>
The downside is, if you deploy your code on a server you don't have access to (meaning you can't enable short tags via php.ini) then you'd have to painfully replace every "<?=" with "<?php echo" BY HAND, find and replace is not allowed.
Eventually, there was a big argument over whether short open tag should be removed in PHP6 (it's not), the biggest reasons for removing it (from what I remember) was that it could conflict with the "<?xml" tag and if you don't have access to php.ini or a modern code editor, you're screwed.
The removal of one of these major problems (by forcing short open tag to work regardless of php.ini settings) brings PHP's short open tag one step closer to being loved and admired by everyone, including YOU, so get used to thinking things like this are great.
As far as chained string offsets, who cares! Long live short open tag! (Sorry I couldn't help it.)
When you share your code with various clients (open source, software seller, ...), you can not assume that short array are on, thus you have to use <?php echo $var ?> everytime instead of the shorter <?=$var?>. Having the second syntax always working solves that, this is on the same level as the short array syntax change, removing a hurdle and letting you concentrate on more important stuff.
> $a = "foo"; $a[0][0]
$a is a string "foo" $a[0] is a string "f" equating to substr($a, 0, 1) $a[0][0] is a string "f" equating to substr($a[0], 0, 1)
> $a[0][1]
This will give an undefined index error, same thing as $a[42] for exemple, since index 1 doesn't exists in $a[0] (= "f")
Is this really a huge concern? I guess I just have $tockholm syndrome at this point, and am used to writing <?php echo $var; ?> explicitly every time, precisely for the reasons you mentioned. It's one less thing to worry about.
This allows short tags to be disabled for XML clash-avoidance while still allowing the user to use the short-form of echo.
How is it weird and stupid? <?php echo $var ?> is better than <?= $var ?> ?
It makes sense when you think of it in offsets. $string[offset] means that given $a = 'foo' then $a[0] is f and given $a = 'f' then $a[0] is f. Thus $a[0][0] would be the first offset of the first offset of "foo". $a[0][1] would not be valid, of course.
Also it's not really something you should ever use, but it's definitely more consistent than throwing an error.