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