On Fri, Apr 18, 2008 at 10:40 AM, Kalle Sommer Nielsen <[EMAIL PROTECTED]>
wrote:

> Hey Internals
>
> I've been wondering for quite some time why PHP doesn't allow you to
> access
> arrays when you assign it to a value like in Javascript:


My opinion on features such as this is that they provide too much
opportunity to do things in a far less than optimal way. Another feature
that was brought up (allowing method calls directly on the constructor) has
the same problem.

I realize that this type of functionality seems appealing when you need to
operate on only one index of an array or when you only want to make a single
method call on a newly instantiated object. But it is going to do it at the
cost of readability (imo) and in some cases reduce the speed or flexibility
of the code. If you reference the 'index' of the return value of a function
you in effect have lost access to all other indexes in the array. So, as
soon as you need another index you are forced to either rewrite your code to
not access the method directly as an array, or you have to make another full
function call to pull in the value. The same holds true for chaining
function calls onto constructors.

On the other hand it would be fun trying to track down exactly what you
should be expecting from: $var = new
Class()->call1()->property[0]->call2()[1]->wheeeeeee();



> function ArrayTest(Array $range)
> {
>        return($range);
> }
>
> $range = Array(1337 => Array('Hello World'));
>
> echo ArrayTest($range)[1337};
>
>
> I would really like to see this introduced in PHP sometime (Perhaps as an
> extra addition to 5.3's new and sleek features).
>
> This is very useful in a few areas and can save a few lines of code here
> and there.
>
> unfortunately Im not a C Programmer myself else I've would have provided a
> patch for this =/
>
>
> Cheers
>
> Kalle Sommer Nielsen
> Zend Certified Engineer
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to