array(...)[]

php.internals

Klaus Reimer

21 years ago
Hi, I've just seen that finally it's possible to do "$object->getOtherObject()->doSomething()" with PHP5 which was not possible in PHP4. But I wonder why something like this still does not work: $object->returnArray()[$index] returnArray()[$index] array(1,2,3,4)[$index] It would be really cool if a future version of PHP understands the above syntax because currently it's really annoying to access an array element returned from a method/function because the return value must be stored in a temporary variable before it is possible to access elements from that array. Bye K

Markus Fischer

21 years ago
Klaus Reimer wrote:
> I've just seen that finally it's possible to do > "$object->getOtherObject()->doSomething()" with PHP5 which was not > possible in PHP4. But I wonder why something like this still does not work: > > $object->returnArray()[$index] > returnArray()[$index] > array(1,2,3,4)[$index] > > It would be really cool if a future version of PHP understands the above > syntax because currently it's really annoying to access an array element > returned from a method/function because the return value must be stored > in a temporary variable before it is possible to access elements from > that array.
I'm seconding this strongly. One of the most useful enhancements for meare, as you mention, $object->getOtherObject()->doSomething(), and the foreach ($a as $b => &c) syntax. Direct array referencing would be #3 for me [besides all the suport oo features] ;) - Markus