Re: Unexpected behavior of $this->$propertyName[...]

From: Date: Thu, 15 Jan 2009 23:04:36 +0000
Subject: Re: Unexpected behavior of $this->$propertyName[...]
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-42652@lists.php.net to get a copy of this message
Hello, On Thu, Jan 15, 2009 at 8:24 PM, Robert Lemke <robert@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

« previous php.internals (#42652) next »