#41641 [Opn->Bgs]: Indirect Modification Notice due to modification using __set

From: Date: Mon, 25 Jun 2007 19:11:26 +0000
Subject: #41641 [Opn->Bgs]: Indirect Modification Notice due to modification using __set
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-114213@lists.php.net to get a copy of this message
 ID:               41641
 Updated by:       tony2001@php.net
 Reported By:      asnyder at mddev dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Linux Fedora Core 4
 PHP Version:      5.2.3
 New Comment:

The __get() function returns by value, not by reference, hence the
warning.


Previous Comments:
------------------------------------------------------------------------

[2007-06-11 14:57:33] asnyder at mddev dot com

How is this bogus? The code DOES indeed make a change. Why should one
have to call SetSomething, instead of the automatic __set triggering and
making the modification.

I don't understand your logic. I have many applications that use this
logic, and the applicatios worked properly before, with the new notice
they don't, unless I explicitly call the function.

What are your thoughts on this?

------------------------------------------------------------------------

[2007-06-11 14:52:51] derick@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

It did not properly work in PHP 5.1.x either, now we emit this warning
so that you can deal with the broken code.

------------------------------------------------------------------------

[2007-06-08 22:50:01] asnyder at mddev dot com

Description:
------------
Ok, the bug is as follows. If one gets an array, via the __get, and
then continues to modify the subobject properties using a __set. It will
call the __set function, but throw the 

Notice: Indirect modification of overloaded property A::$Test has no
effect in /var/www/html/Tests/PHPBug.php on line 43

In PHP 5.1.2 this process worked fine, but in 5.2.3 it causes the
notice.

Reproduce code:
---------------
class A
{
	private $Test = array("One" => null, 'Two' => null);
	
	function A()
	{
		$this->Test['One'] = new B();
	}
	function __get($val)
	{
		return $this->Test;
	}
}
class B
{
	private $SomeVariable;
	
	function GetSomething(){return $this->SomeVariable;}
	function SetSomething($bool)
	{
		$this->SomeVariable = $bool;
	}
	function __get($val)
	{
		$this->GetSomething();
	}
	function __set($part, $val)
	{
		$this->SetSomething($val);
	}
}
$tmpA = new A();


// Now in PHP 5.1.2 the following code works, in PHP 5.2.3 but throws
the notice Indirect modification of overloaded property
$tmpA->Test['One']->Something = true;
//In PHP 5.2.3 one would have to do the following for the notice not to
throw. Which is not the expected behavior
//$tmpA->Test['One']->SetSomething(true);

Expected result:
----------------
The SetSomething($val) function should be called, and it IS being
called, but with throwing a notice. It should behave like in 5.1.2 and
run the SetSomething($val) function without the notice.

One should NOT have to call $tmpA->Test['One']->SetSomething(true) to
not raise the notice.

Actual result:
--------------
Calls function and throws notice.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41641&edit=1


Thread (14 messages)

« previous php.bugs (#114213) next »