[PHP-DEV] Unexpected behavior of $this-$propertyName[...]
Dear internals, please consider the following code executed with PHP 5.3alpha3: ?php class Foo { protected $foo = array('bar' = 'baz'); public function test() { $propertyName = 'foo'; var_dump(isset($this-foo['bar'])); var_dump(isset($this-$propertyName['bar'])); } } $object = new Foo; $object-test(); ? Expected output: array 'foo' = array 'bar' = string 'quux' (length=4) Actual output: array 'foo' = array 'bar' = string 'baz' (length=3) 'f' = string 'quux' (length=4) Is this a bug or missing feature? Cheers, robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior of $this-$propertyName[...]
On Thu, Jan 15, 2009 at 7:24 PM, Robert Lemke rob...@typo3.org wrote: Dear internals, please consider the following code executed with PHP 5.3alpha3: I suspect neither bug nor feature. I think you expect that $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'. Is this a bug or missing feature? 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. Paul -- Paul Biggar paul.big...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior of $this-$propertyName[...]
Hi Paul, Am 15.01.2009 um 20:35 schrieb Paul Biggar: I suspect neither bug nor feature. I think you expect that $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'. okay, I already suspected something like that but had already suppressed that $string[0] works equally as $string{0}. 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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior of $this-$propertyName[...]
Hello, On Thu, Jan 15, 2009 at 8:24 PM, Robert Lemke rob...@typo3.org wrote: Dear internals, please consider the following code executed with PHP 5.3alpha3: ?php class Foo { protected $foo = array('bar' = 'baz'); public function test() { $propertyName = 'foo'; var_dump(isset($this-foo['bar'])); var_dump(isset($this-$propertyName['bar'])); } } $object = new Foo; $object-test(); ? Expected output: array 'foo' = array 'bar' = string 'quux' (length=4) Actual output: array 'foo' = array 'bar' = string 'baz' (length=3) 'f' = string 'quux' (length=4) Is this a bug or missing feature? It's a simple matter of precedence. You want $this-{$propertyName}['bar']; here Regards Cheers, robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php