ReflectionClass_setStaticPropertyValue_003.phpt 780 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. ReflectionClass::setStaticPropertyValue() - type constraints must be enforced
  3. --FILE--
  4. <?php
  5. class Test {
  6. public static $x;
  7. public static int $y = 2;
  8. }
  9. $rc = new ReflectionClass('Test');
  10. try {
  11. $rc->setStaticPropertyValue("y", "foo");
  12. } catch (TypeError $e) { echo $e->getMessage(), "\n"; }
  13. var_dump(Test::$y);
  14. $rc->setStaticPropertyValue("y", "21");
  15. var_dump(Test::$y);
  16. Test::$x =& Test::$y;
  17. try {
  18. $rc->setStaticPropertyValue("x", "foo");
  19. } catch (TypeError $e) { echo $e->getMessage(), "\n"; }
  20. var_dump(Test::$y);
  21. $rc->setStaticPropertyValue("x", "42");
  22. var_dump(Test::$y);
  23. ?>
  24. --EXPECT--
  25. Cannot assign string to property Test::$y of type int
  26. int(2)
  27. int(21)
  28. Cannot assign string to reference held by property Test::$y of type int
  29. int(21)
  30. int(42)