mirror of
https://github.com/php/php-src.git
synced 2024-12-02 22:34:55 +08:00
7498f0163b
Assign-ops and incdec on overloaded properties are implemented using a read_property followed by write_property. Previously, if __get() returned by-reference, pre-incdec and assign-op additionally also modified the reference, while post-incdec worked correctly. This change synchronizes the three code-paths to not modify the reference. The pre-incdec implementation matches the post-incdec implementation, the assign-op implementation uses a distinct result operand.
48 lines
673 B
PHP
48 lines
673 B
PHP
--TEST--
|
|
Handling of assign-ops and incdecs on overloaded properties using &__get()
|
|
--FILE--
|
|
<?php
|
|
|
|
class Test {
|
|
protected $a = 0;
|
|
protected $b = 0;
|
|
protected $c = 0;
|
|
|
|
public function &__get($name) {
|
|
echo "get($name)\n";
|
|
return $this->$name;
|
|
}
|
|
|
|
public function __set($name, $value) {
|
|
echo "set($name, $value)\n";
|
|
}
|
|
}
|
|
|
|
$test = new Test;
|
|
|
|
var_dump($test->a += 1);
|
|
var_dump($test->b++);
|
|
var_dump(++$test->c);
|
|
|
|
var_dump($test);
|
|
|
|
?>
|
|
--EXPECT--
|
|
get(a)
|
|
set(a, 1)
|
|
int(1)
|
|
get(b)
|
|
set(b, 1)
|
|
int(0)
|
|
get(c)
|
|
set(c, 1)
|
|
int(1)
|
|
object(Test)#1 (3) {
|
|
["a":protected]=>
|
|
int(0)
|
|
["b":protected]=>
|
|
int(0)
|
|
["c":protected]=>
|
|
int(0)
|
|
}
|