bug71018.phpt 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Bug #71018 (ReflectionProperty::setValue() behavior changed)
  3. --FILE--
  4. <?php
  5. class T1 {
  6. public static $data;
  7. public static function getDataBySelf()
  8. {
  9. return self::$data;
  10. }
  11. public static function getDataByStatic()
  12. {
  13. return static::$data;
  14. }
  15. }
  16. class T2 extends T1 {}
  17. $Prop1 = new ReflectionProperty(T1::class, 'data');
  18. $Prop2 = new ReflectionProperty(T2::class, 'data');
  19. // #1
  20. // prints: hello, hello in PHP5, but world, hello in PHP7 - not OK
  21. $Prop1->setValue(\T1::class, "world");
  22. $Prop2->setValue(\T2::class, 'hello');
  23. var_dump("T2::self = " . T2::getDataBySelf());
  24. var_dump("T2::static = " . T2::getDataByStatic());
  25. // #2
  26. // prints: hello, hello in both PHP5 and PHP7 - OK
  27. T1::$data = "world";
  28. T2::$data = 'hello';
  29. var_dump("T2::self = " . T2::getDataBySelf());
  30. var_dump("T2::static = " . T2::getDataByStatic());
  31. ?>
  32. --EXPECT--
  33. string(16) "T2::self = hello"
  34. string(18) "T2::static = hello"
  35. string(16) "T2::self = hello"
  36. string(18) "T2::static = hello"