Live data from Hacker News

Short array syntax finally in PHP 5.4

svn.php.net

31–40 of 80 posts

Re: Short array syntax finally in PHP 5.4

#31

Earlier quoted context omitted.

It's not quite what you're asking for, but there is a way to handle array results from functions where you know the number of elements that will be returned. For example: // explode splits the string on the provided boundary // and returns an array containing each segment. // using list() we can assign the two segments to two // variables within the same statement $size = "1000x1000"; list( $width, $height ) = explod…

Ah yes, I love nothing more than functions on the left side of assignment. Edit: Yes, it is a special form, but its still irregular, and that makes it shitty.

It's a pretty common feature of a lot of languages (Python, Perl, etc) so it's really not that irregular.

Re: Short array syntax finally in PHP 5.4

#32
post #24
post #20

But PHP isn't a transmitted language like javascript, why even bother? It will only make the parser slower?

They're trying to be nicer to the humans. (Though IMO, any human who wanted to be kind to himself would just not use PHP to begin wtih.)

Right now those humans would not choose to start a project in php, but a few years ago there were not too much alternatives. It's not for nothing that the world's second biggest website is written in php.

Re: Short array syntax finally in PHP 5.4

#33
Just looked through the RFCs... and I'm a bit surprised noone proposed unification of types yet. It seems a bit silly that the resources, objects, arrays, strings are different types at the language level. They could throw out / reorganise a lot of the randomly named functions this way. Just add the proper methods to the actual types and sort out the (haystack, needle) order, underscores or lack of them, etc.

Re: Short array syntax finally in PHP 5.4

#34
That's good to see, but like many have said, I'd really like to see proper OO stuff like $myArray->pop();

What about short object declaration syntax:

$obj = { param:'blah' };

PHP already has stdClass, so I doubt it would take much of a parser change to implement that.

Re: Short array syntax finally in PHP 5.4

#35
post #18

My big complaint about arrays wasn't declaring them. It was the endless array functions you have to use afterwards. array_push array_pop array_slice array_shift array_unshift array_map array_key_exists It kind of feels like they missed the point, saving 5 characters when you declare the array once, ignoring all of the other operations you do afterwards. And this RFC, simple as it is, took 3.5 years to come to fruitio…

Not to mention the wonderfully inconsistent count() and sort(). Pah.

Re: Short array syntax finally in PHP 5.4

#36
Still strikes me as a useless bit of syntactic sugar. Is it really that much work to write array('foo' => 'bar')? As far as I can tell, writing ['foo' => 'bar'] isn't that much shorter in the first place.

sigh Can the PHP devs focus on the real problems now? cough Unicode anyone? Ridiculously inconsistent naming of string and array functions? The woefully incomplete and useless STL? The lack of OO in arrays and strings?

Re: Short array syntax finally in PHP 5.4

#37
post #36

Still strikes me as a useless bit of syntactic sugar. Is it really that much work to write array('foo' => 'bar')? As far as I can tell, writing ['foo' => 'bar'] isn't that much shorter in the first place. sigh Can the PHP devs focus on the real problems now? cough Unicode anyone? Ridiculously inconsistent naming of string and array functions? The woefully incomplete and useless STL? The lack of OO in arrays and strin…

Hey, I've been complaining about PHP's lack of Unicode support forever. Every time I do, though, an apologist comes out of the woodwork to tell me about the mb_*() functions. Apparently the PHP community is quite comfortable not caring about non-ASCII characters.

Re: Short array syntax finally in PHP 5.4

#38
post #29
post #25

Earlier quoted context omitted.

Hard to say that it is simple unless you know the internals.

2 lines in the parser: http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_langua... The RFC ( https://wiki.php.net/rfc/shortsyntaxforarrays ) was actually rejected by the developers, I think it's only really been put in to appease large userland pressure. Find it rather amusing that a 2 change to the parser for an alias would be rejected on 'maintainability' grounds.

The voting results on the RFC page is from 2008 when it was rejected. The recent vote that decided its inclusion was here: https://wiki.php.net/todo/php54/vote. I think it had pretty solid support from core developers as well as userland people this time around.

Re: Short array syntax finally in PHP 5.4

#39
post #36

Still strikes me as a useless bit of syntactic sugar. Is it really that much work to write array('foo' => 'bar')? As far as I can tell, writing ['foo' => 'bar'] isn't that much shorter in the first place. sigh Can the PHP devs focus on the real problems now? cough Unicode anyone? Ridiculously inconsistent naming of string and array functions? The woefully incomplete and useless STL? The lack of OO in arrays and strin…

Agreed. I don't see how this solves a real problem other than just another way to write the code, which, I guess, is the whole point of this update.

Re: Short array syntax finally in PHP 5.4

#40
post #36

Still strikes me as a useless bit of syntactic sugar. Is it really that much work to write array('foo' => 'bar')? As far as I can tell, writing ['foo' => 'bar'] isn't that much shorter in the first place. sigh Can the PHP devs focus on the real problems now? cough Unicode anyone? Ridiculously inconsistent naming of string and array functions? The woefully incomplete and useless STL? The lack of OO in arrays and strin…

Hey, I've been complaining about PHP's lack of Unicode support forever. Every time I do, though, an apologist comes out of the woodwork to tell me about the mb_*() functions. Apparently the PHP community is quite comfortable not caring about non-ASCII characters.

I brought down a production site by innocently changing some string ops to mb_* string ops. It turns out that they're so slow as to be useless.
Post reply on HN