|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-24 06:55 UTC] 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'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 11:00:02 2025 UTC |
I don't know if this bug has been fixed by this point, but I would like to confirm it in PHP version 5.2.4, in Ubuntu 8.04. It's fairly simple to invoke the bug. Essentially, when you access a value in an ArrayObject that doesn't exist, you seem to get NULL and you're able to treat the empty "NULL" value returned by an array as if it were an array. I've had a look around, and I can't find any other mention of the bug, so I'm kind of assuming it's still present. $array = new ArrayObject(); $array['notinarray'][] = "value"; var_dump($var['something']); var_dump($var2['somethingelse']); var_dump($var3[0]); Output: array(1) { [0]=> string(5) "value" } array(1) { [0]=> string(5) "value" } string(5) "value"