ReflectionProperty_basic2.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. --TEST--
  2. Test usage of ReflectionProperty methods isDefault(), getModifiers(), getDeclaringClass() and getDocComment().
  3. --INI--
  4. opcache.save_comments=1
  5. --FILE--
  6. <?php
  7. function reflectProperty($class, $property) {
  8. $propInfo = new ReflectionProperty($class, $property);
  9. echo "**********************************\n";
  10. echo "Reflecting on property $class::$property\n\n";
  11. echo "isDefault():\n";
  12. var_dump($propInfo->isDefault());
  13. echo "getModifiers():\n";
  14. var_dump($propInfo->getModifiers());
  15. echo "getDeclaringClass():\n";
  16. var_dump($propInfo->getDeclaringClass());
  17. echo "getDocComment():\n";
  18. var_dump($propInfo->getDocComment());
  19. echo "\n**********************************\n";
  20. }
  21. class TestClass {
  22. public $pub;
  23. static public $stat = "static property";
  24. /**
  25. * This property has a comment.
  26. */
  27. protected $prot = 4;
  28. private $priv = "keepOut";
  29. }
  30. reflectProperty("TestClass", "pub");
  31. reflectProperty("TestClass", "stat");
  32. reflectProperty("TestClass", "prot");
  33. reflectProperty("TestClass", "priv");
  34. ?>
  35. --EXPECTF--
  36. **********************************
  37. Reflecting on property TestClass::pub
  38. isDefault():
  39. bool(true)
  40. getModifiers():
  41. int(1)
  42. getDeclaringClass():
  43. object(ReflectionClass)#%d (1) {
  44. ["name"]=>
  45. string(9) "TestClass"
  46. }
  47. getDocComment():
  48. bool(false)
  49. **********************************
  50. **********************************
  51. Reflecting on property TestClass::stat
  52. isDefault():
  53. bool(true)
  54. getModifiers():
  55. int(17)
  56. getDeclaringClass():
  57. object(ReflectionClass)#%d (1) {
  58. ["name"]=>
  59. string(9) "TestClass"
  60. }
  61. getDocComment():
  62. bool(false)
  63. **********************************
  64. **********************************
  65. Reflecting on property TestClass::prot
  66. isDefault():
  67. bool(true)
  68. getModifiers():
  69. int(2)
  70. getDeclaringClass():
  71. object(ReflectionClass)#%d (1) {
  72. ["name"]=>
  73. string(9) "TestClass"
  74. }
  75. getDocComment():
  76. string(%d) "/**
  77. * This property has a comment.
  78. */"
  79. **********************************
  80. **********************************
  81. Reflecting on property TestClass::priv
  82. isDefault():
  83. bool(true)
  84. getModifiers():
  85. int(4)
  86. getDeclaringClass():
  87. object(ReflectionClass)#%d (1) {
  88. ["name"]=>
  89. string(9) "TestClass"
  90. }
  91. getDocComment():
  92. bool(false)
  93. **********************************