Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. <?php
  2.  
  3. class A {
  4. private $data;
  5.  
  6. public function setData($value)
  7. {
  8. $this->data = $value;
  9. }
  10. }
  11.  
  12. $a = new A;
  13. $a->setData('hello world');
  14. #echo $a->data; //error
  15.  
  16. $reflector = new ReflectionClass('A');
  17. $properties = $reflector->getProperties();
  18.  
  19. foreach ($properties as $property) {
  20. $property->setAccessible(true);
  21. echo $property->getValue($a) . PHP_EOL; // hello world
  22. #$property->setAccessible(false);
  23. #echo $property->getValue($a) . PHP_EOL; // error
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement