# array(...)[]

- Thread: https://externals.io/message/13363
- Original archive: https://news-web.php.net/php.internals/13363
- Started by Klaus Reimer on 2004-10-17T14:39:55+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13363 — Klaus Reimer — 2004-10-17T14:39:55+00:00

URL: https://externals.io/message/13363#13363

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

---

## #13365 — Markus Fischer — 2004-10-17T16:33:36+00:00

URL: https://externals.io/message/13363#13365 · In reply to: #13363

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
