|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2004-10-11 11:24 UTC] php at hartwerk dot com
 Description:
------------
When there is a function on the right-hand side of an assignment operator expression, and the variable is to be accessed via __get/__set, the operation yields wrong results. 
Reproduce code:
---------------
class Container
{
	public function __get( $what )
	{
		return $this->_p[ $what ];
	}
	
	public function __set( $what, $value )
	{
		$this->_p[ $what ] = $value;
	}
	
	private $_p = array();
}
$c = new Container();
$c->a = 1;
$c->a += 1;
print $c->a;	// --> 2
print " - ";
$c->a += max( 0, 1 );
print $c->a;	// --> 4 (!)
Expected result:
----------------
2 - 3
Actual result:
--------------
2 - 4
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 04:00:01 2025 UTC | 
This code works if you return the value from _get via reference.... try: public function &__get( $what ) { return $this->_p[ $what ]; }