3v4l.org

run code in 300+ PHP versions simultaneously
<?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));

preferences:
40.12 ms | 402 KiB | 5 Q