Created
February 11, 2022 18:51
-
-
Save denizozturk/89bc0210944cd37835919d69ca7981f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Access/modify any instance private property. | |
| */ | |
| class Invade | |
| { | |
| public function __construct( | |
| protected $instance, | |
| protected $setter, | |
| protected $getter | |
| ) { | |
| } | |
| public function __get($property) | |
| { | |
| return $this->getter->call($this->instance, $property); | |
| } | |
| public function __set($property, $value) | |
| { | |
| $this->setter->call($this->instance, $property, $value); | |
| } | |
| } | |
| /** | |
| * EXAMPLE: | |
| * | |
| * class Foo { | |
| * private $property = 'bar'; | |
| * } | |
| * | |
| * $foo = new Foo(); | |
| * $invade = new Invade($foo); | |
| * | |
| * echo $invade->property; // bar | |
| * $invade->property = 'foo bar'; | |
| * echo $invade->property; // foo bar | |
| * | |
| * Source: jszobody/Undies.php | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment