#42409 [Opn->Fbk]: -> operator permanently damaged after assigning value to overloaded variable
| From: | jani@php.net | Date: | Fri, 24 Aug 2007 09:59:51 +0000 |
| Subject: | #42409 [Opn->Fbk]: -> operator permanently damaged after assigning value to overloaded variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116597@lists.php.net to get a copy of this message | ||
ID: 42409
Updated by: jani@php.net
Reported By: luke dot mcildoon at niche dot com dot au
-Status: Open
+Status: Feedback
Bug Type: Scripting Engine problem
Operating System: Windows Vista 32-bit
PHP Version: 5.2.3
New Comment:
How about you first provided an example script that has some way of
working even the wrong way? The one here just says "Fatal error: Call to
undefined function session()"
Previous Comments:
------------------------------------------------------------------------
[2007-08-24 06:55:54] luke dot mcildoon at niche dot com dot au
Description:
------------
I have a class that returns an array by reference using __get(). As
soon as you try to set a 2+ dimension on the array, the -> operator
returns whatever you tried to assign to the referenced array.
ie.
session()->session['foo'][] = 'test';
print_r($this->var); #[0] => 'test'
print_r($asdf->ghjk); #[0] => 'test'
Basically, from any point after the first example line is used, any use
of the -> operator, regardless of the object being referenced, will
return whatever you tried to assign to the referenced array.
Reproduce code:
---------------
class session extends ArrayObject
{
public $data = array();
public function &__get($var)
{
if($var == 'session')
{
return $this;
}
}
}
session()->session[][] = 'test';
print_r($this->var);
print_r($anything->var);
print_r($this->foobar);
Expected result:
----------------
The actual value of $this->var, then undefined property warnings.
Actual result:
--------------
[0] => 'test'
[0] => 'test'
[0] => 'test'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42409&edit=1