Last active
December 10, 2015 22:59
-
-
Save kopiro/4506417 to your computer and use it in GitHub Desktop.
Export all properties, including private/protected/public of an object.
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 | |
| /* The function */ | |
| function ∫($o) | |
| { | |
| $class_regex = "[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"; | |
| $code = preg_replace("#{$class_regex}::__set_state#", 'return', var_export($o,1)); | |
| return eval($code.';'); | |
| } | |
| /* end function */ | |
| class A | |
| { | |
| private $var = '1'; | |
| private $arr = array(1, 2, 3, array('a','b', array(1,3)); | |
| public $pubvar = 3; | |
| }; | |
| $a = new A(); | |
| $object = ∫($a); | |
| var_dump($object); | |
| var_dump($object["arr"]); | |
| // note that "arr" is private. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment