- var_dump: documentation ( source)
- get_object_vars: documentation ( source)
- method_exists: documentation ( source)
- ucfirst: documentation ( source)
<?php
class Test
{
public $foo = 10;
protected $bar = 12;
private $meh = 14;
/**
* @param string $key
* @return boolean
*/
public function offsetExists($key)
{
return isset($this->{$key});
}
/**
* @param string $key
* @return boolean
*/
public function offsetGet($key)
{
return method_exists($this, 'get'. ucfirst($key)) ? $this->{'get'. ucfirst($key)} : $this->{$key};
}
/**
* @param string $key
* @param mixed $value
*/
public function offsetSet($key, $value)
{
method_exists($this, 'set'. ucfirst($key)) ? $this->{'set'. ucfirst($key)}($value) : $this->{$key} = $value;
}
/**
* @param string $key
*/
public function offsetUnset($key)
{
unset($this->{$key});
}
}
$test = new Test;
var_dump(get_object_vars($test));
foreach($test as $param)
{
echo $param;
}