Skip to content

Instantly share code, notes, and snippets.

@kosinix
Created September 17, 2014 01:37
Show Gist options
  • Select an option

  • Save kosinix/d35da99fc5d679875051 to your computer and use it in GitHub Desktop.

Select an option

Save kosinix/d35da99fc5d679875051 to your computer and use it in GitHub Desktop.
Get all class properties at once and put it in an array
<?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