php-src/Zend/tests/assign_ref_to_overloaded_prop.phpt
Nikita Popov d877d18676 Error on by-ref assign to overloaded prop returning ref
This error was already thrown if __get() was used -- however not
if it returned by reference. This is incorrect, because the
reference return makes no difference to a by-reference assignment,
which has reference-breaking semantics. The result was that the
assignment was accepted silently, even though it didn't do anything
(not even the value was assigned, let alone the reference).
2018-06-09 18:42:22 +02:00

24 lines
417 B
PHP

--TEST--
Cannot assign by reference to overloaded object, even if __get() returns by-ref
--FILE--
<?php
class Test {
private $x;
public function &__get($name) {
return $this->x;
}
}
$test = new Test;
$y = 5;
$test->x =& $y;
var_dump($test->x);
?>
--EXPECTF--
Fatal error: Uncaught Error: Cannot assign by reference to overloaded object in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d