006.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --TEST--
  2. ReflectionClass::[gs]etStaticPropertyValue
  3. --FILE--
  4. <?php
  5. /* ReflectionClass cannot touch protected or private static properties */
  6. /* ReflectionClass cannot create or delete static properties */
  7. Class Test
  8. {
  9. static public $pub = 'pub';
  10. static protected $pro = 'pro';
  11. static private $pri = 'pri';
  12. static function testing()
  13. {
  14. $ref = new ReflectionClass('Test');
  15. foreach(array('pub', 'pro', 'pri') as $name)
  16. {
  17. try
  18. {
  19. var_dump($ref->getStaticPropertyValue($name));
  20. var_dump($ref->getStaticPropertyValue($name));
  21. $ref->setStaticPropertyValue($name, 'updated');
  22. var_dump($ref->getStaticPropertyValue($name));
  23. }
  24. catch(Exception $e)
  25. {
  26. echo "EXCEPTION\n";
  27. }
  28. }
  29. }
  30. }
  31. Class TestDerived extends Test
  32. {
  33. // static public $pub = 'pub';
  34. // static protected $pro = 'pro';
  35. static private $pri = 'pri';
  36. static function testing()
  37. {
  38. $ref = new ReflectionClass('Test');
  39. foreach(array('pub', 'pro', 'pri') as $name)
  40. {
  41. try
  42. {
  43. var_dump($ref->getStaticPropertyValue($name));
  44. var_dump($ref->getStaticPropertyValue($name));
  45. $ref->setStaticPropertyValue($name, 'updated');
  46. var_dump($ref->getStaticPropertyValue($name));
  47. }
  48. catch(Exception $e)
  49. {
  50. echo "EXCEPTION\n";
  51. }
  52. }
  53. }
  54. }
  55. $ref = new ReflectionClass('Test');
  56. foreach(array('pub', 'pro', 'pri') as $name)
  57. {
  58. try
  59. {
  60. var_dump($ref->getStaticPropertyValue($name));
  61. var_dump($ref->getStaticPropertyValue($name));
  62. $ref->setStaticPropertyValue($name, 'updated');
  63. var_dump($ref->getStaticPropertyValue($name));
  64. }
  65. catch(Exception $e)
  66. {
  67. echo "EXCEPTION\n";
  68. }
  69. }
  70. Test::testing();
  71. TestDerived::testing();
  72. ?>
  73. --EXPECT--
  74. string(3) "pub"
  75. string(3) "pub"
  76. string(7) "updated"
  77. string(3) "pro"
  78. string(3) "pro"
  79. string(7) "updated"
  80. string(3) "pri"
  81. string(3) "pri"
  82. string(7) "updated"
  83. string(7) "updated"
  84. string(7) "updated"
  85. string(7) "updated"
  86. string(7) "updated"
  87. string(7) "updated"
  88. string(7) "updated"
  89. string(7) "updated"
  90. string(7) "updated"
  91. string(7) "updated"
  92. string(7) "updated"
  93. string(7) "updated"
  94. string(7) "updated"
  95. string(7) "updated"
  96. string(7) "updated"
  97. string(7) "updated"
  98. string(7) "updated"
  99. string(7) "updated"
  100. string(7) "updated"