php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42409 -> operator permanently damaged after assigning value to overloaded variable
Submitted: 2007-08-24 06:55 UTC Modified: 2007-09-01 01:00 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: luke dot mcildoon at niche dot com dot au Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.2.3 OS: Windows Vista 32-bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
32 - 23 = ?
Subscribe to this entry?

 
 [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'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-24 09:59 UTC] jani@php.net
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()"
 [2007-09-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-05-02 02:09 UTC] ayvah at nessness dot org
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"
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Nov 29 14:04:16 2022 UTC