- property_exists: documentation ( source)
- var_dump: documentation ( source)
<?php
class Baz
{
protected $foo;
protected $bar;
}
class Proxy
{
private $realObj;
public function __construct($realObj)
{
$this->realObj = $realObj;
}
public function extract(array $data = array())
{
foreach ($data as $key => $val) {
if (property_exists($this->realObj, $key)) {
$this->$key = $val;
}
}
return $this;
}
}
$data = array('foo' => 'bar');
$baz = new Baz;
$proxy = new Proxy($baz);
var_dump($proxy->extract($data));