Live data from Hacker News

PHP 5.4.0 released

php.net

41–50 of 103 posts

Re: PHP 5.4.0 released

#41
post #5

I'm glad to see the short array syntax. Having strayed from PHP for a while to work on Ruby and JavaScript I'm really enjoying the ability to leave out semicolons in unambiguous end-of-line situations. Would love to see that make it into PHP at some point.

The best part of short array syntax is that now you don't need named parameters to be supported by the language.

    function foo($opts) {
      echo $opts['source'] . $opts['destination'];
    }
    
    // just one extra pair of [] needed instead of new array()
    foo(['source' => '/123', 'destination' => '/abc']);

Re: PHP 5.4.0 released

#42
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.

There's nothing stopping you from using, say, remi or webtatic repos on CentOS.

Re: PHP 5.4.0 released

#43

This is a nice list of improvements. As someone who spends a lot of the day in PHP-land, this is going to make me happy. As someone who also controls our entire server stack, waiting for someone else to decide to upgrade will not be a problem :) I'm glad the PHP devs are starting to actually make it a "real" language. It seems like PHP has always been the fat kid bumbling along behind everyone shouting "wait up guys!…

> waiting for someone else to decide to upgrade will not be a problem :)

It is sad that a lot of servers are not like this, and PHP 5.4 will take ages to appear, if at all.

Heck, I know of a hosting company still using PHP4.

Re: PHP 5.4.0 released

#44
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!

sorry when you are motoring through code typing I understand for general php portability that its better to use the <?php echo vs <?=$whatever syntax, but less code is a good thing.

Re: PHP 5.4.0 released

#45
post #41
post #5

I'm glad to see the short array syntax. Having strayed from PHP for a while to work on Ruby and JavaScript I'm really enjoying the ability to leave out semicolons in unambiguous end-of-line situations. Would love to see that make it into PHP at some point.

The best part of short array syntax is that now you don't need named parameters to be supported by the language. function foo($opts) { echo $opts['source'] . $opts['destination']; } // just one extra pair of [] needed instead of new array() foo(['source' => '/123', 'destination' => '/abc']);

You could do that before short syntax:

    foo(array('source' => '/123', 'destination' => '/abc'));
Short syntax will make it less repetitive though. You can also use something like array_merge to emulate jQuery's $.extend for creating defaults.

Re: PHP 5.4.0 released

#46
post #41
post #5

I'm glad to see the short array syntax. Having strayed from PHP for a while to work on Ruby and JavaScript I'm really enjoying the ability to leave out semicolons in unambiguous end-of-line situations. Would love to see that make it into PHP at some point.

The best part of short array syntax is that now you don't need named parameters to be supported by the language. function foo($opts) { echo $opts['source'] . $opts['destination']; } // just one extra pair of [] needed instead of new array() foo(['source' => '/123', 'destination' => '/abc']);

While I agree that it makes it easier to hack in that functionality, it would still be very useful to have named parameters for functions that don't implement that functionality.

For example, fgetcsv takes parameters for delimiter, enclosure, and escape char (as of 5.3). Right now, if I want to specify a different enclosure, I'm forced to specify a delimiter even if I still want to use the default. I'd much prefer the ability to tell the function call that I want to override the enclosure and leave the delimiter alone.

Re: PHP 5.4.0 released

#47

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…

The www.php.net mirror will only be rsynced tomorrow, for now use http://docs.php.net/manual/en/migration54.php instead to get infos about 5.4 features. It's a good bit more up to date.

Re: PHP 5.4.0 released

#48
Also awesome:

"Arrays cast from SimpleXMLElement now always contain all nodes instead of just the first matching node. All SimpleXMLElement children are now always printed when using var_dump(), var_export() and print_r()."

Re: PHP 5.4.0 released

#49
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.?

Many 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:

(Personal Preference Alert!) Is easier to read, faster to type and easier for designers to handle than:

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 "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 "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.)

Re: PHP 5.4.0 released

#50

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…

I am curious what the internal hang up is which prevents:

funcReturnsFunc(1)(2)

Post reply on HN