New dereferencing syntaxes in 5.4
| From: | Nikita Popov | Date: | Sun, 20 Nov 2011 15:42:51 +0000 |
| Subject: | New dereferencing syntaxes in 5.4 | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-56441@lists.php.net to get a copy of this message | ||
Hi internals!
I want to discuss some details of the new dereferencing syntaxes which
were introduced in 5.4.
1. I already mentioned lack of support for dereferencing using the
alternative array syntax earlier
(http://markmail.org/thread/j6rs3bzgzhxmco7n) but there was no
conclusion on that topic. Now the (new A)[0] dereferencing syntax
landed without alternative syntax too. Does this mean that the general
consensus is to deprecate and remove the {} syntax altogether in the
future?
2. PHP always supported doing $arr[0]() and 5.4 added the reverse
func()[0]. The addition seems slightly inconsistent though, as the
combination of both does not work: func()[0]() will result in a syntax
error. Same applies to method array dereferencing. Is this
intentional?
3. The new expression method, property and array dereferencing
syntaxes were added in expr_without_variable. I am not sure whether
this was intentional or not. That way (new A)->b will not be a
variable (in the parser sense), whereas $a->b will. What is the impact
of this? One thing that will not work is doing (new A)->b = 'c'. I
know, this looks fairly stupid, but if you consider that A might
overload the __set operation it might actually make sense. (It won't
make much sense, but hey, (new A)[0] doesn't make much sense to me
either). Other areas that might be affected are return by reference,
pass by reference and iterate by reference (but I didn't test this).
So, I know, those are all edge cases, so leaving them as is won't hurt
much. Still I think it's better to discuss them ;)
Nikita