1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
--TEST--
Virtual get hook allows returning by reference
--FILE--
<?php
class Test {
private $_prop;
public $prop {
&get => $this->_prop;
set { $this->_prop = $value; }
}
}
function inc(&$ref) {
$ref++;
}
$test = new Test();
$test->prop = 42;
$prop = &$test->prop;
$prop++;
var_dump($test);
var_dump($test->prop);
unset($prop);
inc($test->prop);
var_dump($test);
var_dump($test->prop);
?>
--EXPECT--
object(Test)#1 (1) {
["_prop":"Test":private]=>
&int(43)
}
int(43)
object(Test)#1 (1) {
["_prop":"Test":private]=>
int(44)
}
int(44)
|