#30394 [Csd->Opn]: Assignment operators yield wrong result with __get/__set
| From: | tony2001@php.net | Date: | Thu, 04 Nov 2004 15:10:05 +0000 |
| Subject: | #30394 [Csd->Opn]: Assignment operators yield wrong result with __get/__set | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-68700@lists.php.net to get a copy of this message | ||
ID: 30394
Updated by: tony2001@php.net
Reported By: php at hartwerk dot com
-Status: Closed
+Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Linux
PHP Version: 5.0.2
New Comment:
It's 5.0.x specific bug.
Previous Comments:
------------------------------------------------------------------------
[2004-11-04 16:06:31] thekid@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
Works fine with 5.1-CVS, outputting "2 - 3"
------------------------------------------------------------------------
[2004-10-15 18:46:51] php at hartwerk dot com
An easier work-around would be $c->a = $c->a + max( 0, 1 ), but
work-arounds do not solve bugs..
------------------------------------------------------------------------
[2004-10-15 12:13:47] ante dot dfg at moj dot net
This code works if you return the value from _get via reference....
try:
public function &__get( $what ) {
return $this->_p[ $what ];
}
------------------------------------------------------------------------
[2004-10-11 11:24:19] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30394&edit=1