bug80037.phpt 592 B

1234567891011121314151617181920212223242526272829303132
  1. --TEST--
  2. Bug #80037: Typed property must not be accessed before initialization when __get() declared
  3. --FILE--
  4. <?php
  5. final class A
  6. {
  7. public string $a;
  8. public static function fromArray(array $props): self
  9. {
  10. $me = new static;
  11. foreach ($props as $k => &$v) {
  12. $me->{$k} = &$v; # try to remove &
  13. }
  14. return $me;
  15. }
  16. public function __get($name)
  17. {
  18. throw new \LogicException("Property '$name' is not defined.");
  19. }
  20. }
  21. var_dump(A::fromArray(['a' => 'foo']));
  22. ?>
  23. --EXPECT--
  24. object(A)#1 (1) {
  25. ["a"]=>
  26. string(3) "foo"
  27. }