-
-
Save TheDistantSea/7e88404bfa6a5fb3ff47 to your computer and use it in GitHub Desktop.
PHP - Read/Write public/protected/private object property
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 | |
| function stole($object,$property){ | |
| $dict = (array)$object; | |
| $class = get_class($object); | |
| return isset($dict[$property])? | |
| $dict[$property]:(isset($dict["\0*\0$property"])? | |
| $dict["\0*\0$property"]:(isset($dict["\0$class\0$property"])? | |
| $dict["\0$class\0$property"]:null)); | |
| } | |
| class Safe { | |
| private $content = 'gold'; | |
| } | |
| $mySafe = new Safe(); | |
| echo "I've robbed your ",stole($mySafe,'content'),"!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment