Re: Feature request
| From: | Sebastian Bergmann | Date: | Fri, 10 Nov 2006 11:55:45 +0000 |
| Subject: | Re: Feature request | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-26460@lists.php.net to get a copy of this message | ||
Dmitry Shirokov wrote:
> <?php
> function foo()
> {
> return array(1,2,3,4,5,6);
> }
>
> echo foo()[4]; // <---- it that
> // or may be (foo())[4] ?
>
>
> // instead of
> $var = foo();
> echo $var[4];
> ?>
Although I am not a huge fan of method chaining in general (see [1]),
I am happy to have it in PHP as it faciliates fluent interfaces [2].
I makes IMHO perfect sense to also allow a similar syntax for arrays.
But the implementation should be closed (in the mathematical sense), so
that $o->m()[0]->n() also works, for instance, when m() returns an
array that has an object with method n() at index 0.
--
[1] http://en.wikipedia.org/wiki/Law_of_Demeter
[2] http://www.martinfowler.com/bliki/FluentInterface.html
--
Sebastian Bergmann http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69