assign_obj_exceptions.phpt 895 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Make sure various ASSIGN_OBJ exceptions are not optimized away
  3. --FILE--
  4. <?php
  5. class Test {
  6. public stdClass $x;
  7. }
  8. function test_invalid_prop_type() {
  9. $test = new Test;
  10. $test->x = "";
  11. }
  12. function test_invalid_prop_name(string $name) {
  13. $test = new stdClass;
  14. $test->$name = null;
  15. }
  16. function test_invalid_obj_type($c) {
  17. if ($c) {
  18. $test = new stdClass;
  19. } else {
  20. $test = null;
  21. }
  22. $test->x = "";
  23. }
  24. try {
  25. test_invalid_prop_type();
  26. } catch (TypeError $e) {
  27. echo $e->getMessage(), "\n";
  28. }
  29. try {
  30. test_invalid_prop_name("\0");
  31. } catch (Error $e) {
  32. echo $e->getMessage(), "\n";
  33. }
  34. try {
  35. test_invalid_obj_type(false);
  36. } catch (Error $e) {
  37. echo $e->getMessage(), "\n";
  38. }
  39. ?>
  40. --EXPECT--
  41. Cannot assign string to property Test::$x of type stdClass
  42. Cannot access property starting with "\0"
  43. Attempt to assign property "x" on null