inference_001.phpt 729 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Type inference 001: Invalid type narrowing warning
  3. --INI--
  4. opcache.enable=1
  5. opcache.enable_cli=1
  6. opcache.optimization_level=-1
  7. --FILE--
  8. <?php
  9. function test() {
  10. for ($i = 0; $i < 2; $i++) {
  11. $obj->x;
  12. $obj = new stdClass;
  13. }
  14. }
  15. test();
  16. class Test {
  17. public int $x = 1;
  18. }
  19. function test2() {
  20. for ($i = 0; $i < 2; $i++) {
  21. $obj->x;
  22. $obj = new Test;
  23. }
  24. }
  25. test2();
  26. ?>
  27. DONE
  28. --EXPECTF--
  29. Warning: Undefined variable $obj in %s on line %d
  30. Warning: Attempt to read property "x" on null in %s on line %d
  31. Warning: Undefined property: stdClass::$x in %s on line %d
  32. Warning: Undefined variable $obj in %s on line %d
  33. Warning: Attempt to read property "x" on null in %s on line %d
  34. DONE