Re: Unexpected behavior of $this->$propertyName[...]
| From: | Robert Lemke | Date: | Thu, 15 Jan 2009 20:21:04 +0000 |
| Subject: | Re: Unexpected behavior of $this->$propertyName[...] | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-42649@lists.php.net to get a copy of this message | ||
Hi Paul,
Am 15.01.2009 um 20:35 schrieb Paul Biggar:
I suspect neither bug nor feature. I think you expect thatokay, I already suspected something like that but had already suppressed that $string[0] works equally as $string{0}.$this->$propertyName['bar']is the same as:($this->$propertyName)['bar']but in fact it is:$this->($propertyName['bar'])So in your example, 'bar' is the string index 0 for "foo"[0], hence 'f'.
It has been pointed out before that one should be able to index an expression, but currently PHP can only index variables. Personally, it seems like a bug, but I'm not sure whether or not there's consensus.IMO it feels like a bug, although I now understand the reasons. What was the reason again to deprecate curly brackets access in PHP6? It would make the situation clearer in the above example if square brackets would be deprecated instead ... Anyway, thank you for the clarification. Robert