ReflectionProperty_constructor_variation1.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. ReflectionProperty::__construct(): ensure inherited private props can't be accessed through ReflectionProperty.
  3. --FILE--
  4. <?php
  5. class C {
  6. private $p = 1;
  7. static function testFromC() {
  8. try {
  9. $rp = new ReflectionProperty("D", "p");
  10. var_dump($rp);
  11. } catch (Exception $e) {
  12. echo $e->getMessage();
  13. }
  14. }
  15. }
  16. class D extends C{
  17. static function testFromD() {
  18. try {
  19. $rp = new ReflectionProperty("D", "p");
  20. var_dump($rp);
  21. } catch (Exception $e) {
  22. echo $e->getMessage();
  23. }
  24. }
  25. }
  26. echo "--> Reflect inherited private from global scope:\n";
  27. try {
  28. $rp = new ReflectionProperty("D", "p");
  29. var_dump($rp);
  30. } catch (Exception $e) {
  31. echo $e->getMessage();
  32. }
  33. echo "\n\n--> Reflect inherited private from declaring scope:\n";
  34. C::testFromC();
  35. echo "\n\n--> Reflect inherited private from declaring scope via subclass:\n";
  36. D::testFromC();
  37. echo "\n\n--> Reflect inherited private from subclass:\n";
  38. D::testFromD();
  39. ?>
  40. --EXPECTF--
  41. --> Reflect inherited private from global scope:
  42. Property D::$p does not exist
  43. --> Reflect inherited private from declaring scope:
  44. Property D::$p does not exist
  45. --> Reflect inherited private from declaring scope via subclass:
  46. Property D::$p does not exist
  47. --> Reflect inherited private from subclass:
  48. Property D::$p does not exist