Guest User

Untitled

a guest
Oct 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. class Foo
  5. {
  6. private $bar = 'bar';
  7.  
  8. public function outputBar()
  9. {
  10. echo $this->bar . PHP_EOL;
  11. }
  12. }
  13.  
  14. $foo = new Foo();
  15. $foo->outputBar(); // outputs "bar"
  16.  
  17. // Impossible to update bar? Think again!
  18. $ref = new ReflectionObject($foo);
  19. $propertyBar = $ref->getProperty('bar');
  20. $propertyBar->setAccessible(true);
  21. $propertyBar->setValue($foo, 'derp');
  22.  
  23. $foo->outputBar(); // outputs "derp"
Add Comment
Please, Sign In to add comment