Live data from Hacker News

PHP 5.4.0 released

php.net

31–40 of 103 posts

Re: PHP 5.4.0 released

#31

I see a lot of mentions of zend in extension names, function names.. Could someone elaborate how Zend relates to PHP?

Zend Technologies Ltd. is a company started by Zeev Suraski and Andi Gutmans. The product of theirs you most likely heard of is Zend Framework, a PHP framework. It's however not their only product. Another one is the Zend Engine, which is a PHP interpeter and the virtual machine at the heart of PHP and the reason there are references to Zend all over the place.

Re: PHP 5.4.0 released

#32

Big hitters: array dereferencing - $object->method()[$index] is now valid syntax built-in webserver via CLI - php -s - http://php.net/manual/en/features.commandline.webserver.php traits and the insteadof operator - http://php.net/language.oop5.traits.php shortened array syntax - $array = [1, 2, [1, 2, 3], 4]; Finally removed register_globals ;) Default charset of UTF-8! Read all about it! http://www.php.net/manual/en…

Really looking forward to traits. We have some hacks using interfaces and __call that we have been using to try and approximate traits, but the real thing is always much better. :)

Same here. This is a move away from inheritance to mixins. They did a stellar job with it and it's really flexible. Check out http://us2.php.net/traits for the nitty-gritty.

Re: PHP 5.4.0 released

#33
post #21
post #7

Other great little changes: - you can now do function()[0] - Seems like a return to sanity for the PHP team, at least temporarily.. I even kinda like the traits!

How is ' 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.?

> $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.

Re: PHP 5.4.0 released

#34
post #27
post #21

Earlier quoted context omitted.

How is ' 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.?

I 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? is better than ?

Good 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 <%.

Re: PHP 5.4.0 released

#35
post #14

Now the question is, when will this become available in mainstream Linux distributions? I guess Arch et al. will get it pretty quickly, followed by Ubuntu 12.10 or maybe 13.04 depending on how many packages it affects. Good ol' Debian, on the other hand, might or might not get it in time for the Wheezy freeze. CentOS? Forgetaboutit.

I use CentOS in my stack. It's going to get it today. Because I'm going to compile it =)

Re: PHP 5.4.0 released

#36
post #21
post #7

Other great little changes: - you can now do function()[0] - Seems like a return to sanity for the PHP team, at least temporarily.. I even kinda like the traits!

How is ' 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.?

> How is '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 everytime instead of the shorter . 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")

Re: PHP 5.4.0 released

#38
post #14

Now the question is, when will this become available in mainstream Linux distributions? I guess Arch et al. will get it pretty quickly, followed by Ubuntu 12.10 or maybe 13.04 depending on how many packages it affects. Good ol' Debian, on the other hand, might or might not get it in time for the Wheezy freeze. CentOS? Forgetaboutit.

You may want to try DotDeb [1], they already have PHP 5.4 packaged for Debian :-)

[1]: http://www.dotdeb.org/

Re: PHP 5.4.0 released

#39
post #25

From here: http://www.php.net/manual/en/migration54.other.php > Chained string offsets - e.g. $a[0][0] where $a is a string - now work. Can someone explain why this is? I'm sure I'm misunderstanding, but this seems to mean that the following would work: $a = "Hello"; echo $a[0]; //"h" echo $a[0][0]; // also "h"?? What's the point? To avoid failure if I pass a string instead of a 2-dimensional array?

Consistency. Since $a[0] is a string, you would expect $a[0][0] to work too.

Thanks. Let me rework my original question then. Why the hell didn't it always work?

  php > $a = "Hello";
  php > echo $a[0];
  H
  php > echo $a[0][0];
  PHP Fatal error:  Cannot use string offset as an array in php shell code on line 1

Re: PHP 5.4.0 released

#40
post #25

Earlier quoted context omitted.

Consistency. Since $a[0] is a string, you would expect $a[0][0] to work too.

Thanks. Let me rework my original question then. Why the hell didn't it always work? php > $a = "Hello"; php > echo $a[0]; H php > echo $a[0][0]; PHP Fatal error: Cannot use string offset as an array in php shell code on line 1

PHP always seemed to have something weird in the parser about subscripts/array indexes. It's been there since I started using it during PHP3. Another similar fix they performed is making func()[0] work - before you had to do $tmp = func(); $tmp[0]. An old, old bug finally fixed.
Post reply on HN