3 ms·
Other great little changes: - you can now do function()[0] - <?= always on despite what you say in the INI - safe_mode always off Seems like a return t
by tlack 15y ago
Other great little changes:
- you can now do function()[0]
- <?= always on despite what you say in the INI
- safe_mode always off
Seems like a return to sanity for the PHP team, at least temporarily.. I even kinda like the traits!
- klausa 15y agoHow is '<?=' being always on great change? I always thought it was weird and kind of stupid, but I'm genuinely curious how is that great thing. 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.?
- there 15y agoI always thought it was weird and kind of stupid, but I'm genuinely curious how is that great thing. How is it weird and stupid? <?php echo $var ?> is better than <?= $var ?> ?
- prodigal_erik 15y agoGood tools complain about <?= because it does not start with a named target. A lot of people just haven't read about the idea behind processing instruction syntax, which is also why we keep seeing mistakes like <%.
- danellis 15y agoA PHP script isn't an XML document, so processing instructions aren't really relevant. Even if your script is outputting XML, the script itself isn't going to be read by an XML parser.
- prodigal_erik 15y agoIt can if you want. It's not that hard to make documents which are valid before and after scripts run. This enables many more tools to work with them.
- function_seven 15y agoI'd say that "<?=" being always-available is a verbosity reduction along the lines of short array syntax. The alternative of using "<?php echo" can be quite noisy for some (me). This allows short tags to be disabled for XML clash-avoidance while still allowing the user to use the short-form of echo.
- chrisrogers 15y agofor '<?=', I see it as a good thing for using php for views. It's faster and more natural to read within typical display markups. Akin to the erb syntax.
- mfjordvald 15y ago> $a = "foo"; $a[0][0] 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.
- nolok 15y ago> How is '<?=' being always on great change? I always thought it was weird and kind of stupid, but I'm genuinely curious how is that great thing. 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")
- pavel_lishin 15y ago> thus you have to use <?php echo $var ?> everytime instead of the shorter <?=$var?> 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.
- ryanac 15y agoMany people write their PHP views in raw PHP to remove the (albeit small) overhead from a templating system. I think this is where the PHP short open tag syntax gets used the most (I know I use it there a lot), this is because: <?=$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.)
- honopu 15y agosorry when you are motoring through code typing <?php echo $var vs <?=$var it gets to be tedious. I understand for general php portability that its better to use the <?php echo vs <?=$whatever syntax, but less code is a good thing.