Live data from Hacker News

Short array syntax finally in PHP 5.4

svn.php.net

21–30 of 80 posts

Re: Short array syntax finally in PHP 5.4

#21

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.

`list` is a special form, not a function.

Re: Short array syntax finally in PHP 5.4

#22
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…

agreed. this is one of my pet peeves with PHP also.

Re: Short array syntax finally in PHP 5.4

#23
post #4

Earlier quoted context omitted.

Uh, why wouldn't [[4, 5, 6], [7, 8, 9], [10, 11, 12]] work? I know PHP has a weird history of rebelling against its C-family-syntax heritage, but requiring the syntax in your example would seem specifically calculated just to make developers' lives harder.

Your example would work, but there's a reason you might want different keys. My company's current web app is written in CakePHP, which has a love for arrays. Some of my queries look like this: $booking = $this->Booking->find('first', array('conditions' => array('Booking.booking_id' => $id), 'contain' => array('Review', 'Desk' => array('fields' => array('provider_id', 'category_id'), 'Provider' => array('city', 'name'…

As an FYI, you might want to look into custom find methods if you haven't already: https://github.com/josegonzalez/documentation/blob/master/03...

Re: Short array syntax finally in PHP 5.4

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

Re: Short array syntax finally in PHP 5.4

#25
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…

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

Re: Short array syntax finally in PHP 5.4

#26
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…

I for one would love to see these replaced or complemented by a more OO syntax like:

[1,2,3]->push(..) [3,5,6,]->pop(..) [7,8,9]->map(..)

etc..

Re: Short array syntax finally in PHP 5.4

#27
post #25
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…

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

And why should everyone know or care about language internals?

Re: Short array syntax finally in PHP 5.4

#28
post #25

Earlier quoted context omitted.

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

And why should everyone know or care about language internals?

If someone is making a statement about how "simple" something is to implement, they should know what they're talking about, no?

Re: Short array syntax finally in PHP 5.4

#29
post #25
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…

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.

Post reply on HN