ReflectionClass_getStaticPropertyValue_001.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. ReflectionClass::getStaticPropertyValue()
  3. --CREDITS--
  4. Robin Fernandes <robinf@php.net>
  5. Steve Seear <stevseea@php.net>
  6. --SKIPIF--
  7. <?php if (version_compare(zend_version(), '2.4.0', '>=')) die('skip ZendEngine 2.3 or below needed'); ?>
  8. --FILE--
  9. <?php
  10. class A {
  11. static private $privateOverridden = "original private";
  12. static protected $protectedOverridden = "original protected";
  13. static public $publicOverridden = "original public";
  14. }
  15. class B extends A {
  16. static private $privateOverridden = "changed private";
  17. static protected $protectedOverridden = "changed protected";
  18. static public $publicOverridden = "changed public";
  19. }
  20. echo "Retrieving static values from A:\n";
  21. $rcA = new ReflectionClass('A');
  22. var_dump($rcA->getStaticPropertyValue("privateOverridden", "default value"));
  23. var_dump($rcA->getStaticPropertyValue("\0A\0privateOverridden"));
  24. var_dump($rcA->getStaticPropertyValue("protectedOverridden", "default value"));
  25. var_dump($rcA->getStaticPropertyValue("\0*\0protectedOverridden"));
  26. var_dump($rcA->getStaticPropertyValue("publicOverridden"));
  27. echo "\nRetrieving static values from B:\n";
  28. $rcB = new ReflectionClass('B');
  29. var_dump($rcB->getStaticPropertyValue("\0A\0privateOverridden"));
  30. var_dump($rcB->getStaticPropertyValue("\0B\0privateOverridden"));
  31. var_dump($rcB->getStaticPropertyValue("\0*\0protectedOverridden"));
  32. var_dump($rcB->getStaticPropertyValue("publicOverridden"));
  33. echo "\nRetrieving non-existent values from A with no default value:\n";
  34. try {
  35. var_dump($rcA->getStaticPropertyValue("protectedOverridden"));
  36. echo "you should not see this";
  37. } catch (Exception $e) {
  38. echo $e->getMessage() . "\n";
  39. }
  40. try {
  41. var_dump($rcA->getStaticPropertyValue("privateOverridden"));
  42. echo "you should not see this";
  43. } catch (Exception $e) {
  44. echo $e->getMessage() . "\n";
  45. }
  46. ?>
  47. --EXPECTF--
  48. Retrieving static values from A:
  49. string(13) "default value"
  50. string(16) "original private"
  51. string(13) "default value"
  52. string(18) "original protected"
  53. string(15) "original public"
  54. Retrieving static values from B:
  55. string(16) "original private"
  56. string(15) "changed private"
  57. string(17) "changed protected"
  58. string(14) "changed public"
  59. Retrieving non-existent values from A with no default value:
  60. Class A does not have a property named protectedOverridden
  61. Class A does not have a property named privateOverridden