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.
Short array syntax finally in PHP 5.4
21–30 of 80 posts
Re: Short array syntax finally in PHP 5.4
#22My 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…
Re: Short array syntax finally in PHP 5.4
#23Earlier 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'…
Re: Short array syntax finally in PHP 5.4
#24But PHP isn't a transmitted language like javascript, why even bother? It will only make the parser slower?
Re: Short array syntax finally in PHP 5.4
#25My 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…
Re: Short array syntax finally in PHP 5.4
#26My 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…
[1,2,3]->push(..) [3,5,6,]->pop(..) [7,8,9]->map(..)
etc..
Re: Short array syntax finally in PHP 5.4
#27My 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
#28Earlier 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?
Re: Short array syntax finally in PHP 5.4
#29My 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.
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.
Re: Short array syntax finally in PHP 5.4
#30But PHP isn't a transmitted language like javascript, why even bother? It will only make the parser slower?