1
0
mirror of https://github.com/php/php-src.git synced 2026-04-10 17:43:13 +02:00
Files
archived-php-src/Zend/tests/bug80037.phpt
Nikita Popov dfaa4768d2 Fix bug #80037
If we're accessing an uninitialized typed property and __get is
defined, don't perform a read_property callback, as __get is
supposed to have no effect on uninitialized typed properties.
Usually it doesn't, but by-reference assignments cannot be
performed through read_property.

I'm deleting the test for bug #80039 again, as it doesn't really
make sense anymore with this fix.
2020-08-31 12:17:00 +02:00

33 lines
532 B
PHP

--TEST--
Bug #80037: Typed property must not be accessed before initialization when __get() declared
--FILE--
<?php
final class A
{
public string $a;
public static function fromArray(array $props): self
{
$me = new static;
foreach ($props as $k => &$v) {
$me->{$k} = &$v; # try to remove &
}
return $me;
}
public function __get($name)
{
throw new \LogicException("Property '$name' is not defined.");
}
}
var_dump(A::fromArray(['a' => 'foo']));
?>
--EXPECT--
object(A)#1 (1) {
["a"]=>
string(3) "foo"
}