Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- class Foo
- {
- private $bar = 'bar';
- public function outputBar()
- {
- echo $this->bar . PHP_EOL;
- }
- }
- $foo = new Foo();
- $foo->outputBar(); // outputs "bar"
- // Impossible to update bar? Think again!
- $ref = new ReflectionObject($foo);
- $propertyBar = $ref->getProperty('bar');
- $propertyBar->setAccessible(true);
- $propertyBar->setValue($foo, 'derp');
- $foo->outputBar(); // outputs "derp"
Add Comment
Please, Sign In to add comment