Created
September 17, 2014 01:37
-
-
Save kosinix/d35da99fc5d679875051 to your computer and use it in GitHub Desktop.
Get all class properties at once and put it in an array
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 | |
| class Foo { | |
| protected $var1; | |
| protected $var2; | |
| /* Get Properties | |
| * | |
| * Get all class properties at once and put it in an array | |
| * | |
| * @return array $class_vars | |
| */ | |
| public function get_properties(){ | |
| $class_vars = get_class_vars(get_class($this)); | |
| foreach($class_vars as $name=>$value){ | |
| $class_vars[$name] = $this->$name; | |
| } | |
| return $class_vars; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment