- var_dump: documentation ( source)
<?php
class Foo
{
private $foo =2;
}
class Hydrator
{
public function getPrivate($obj, $attribute) {
$getter = function(){return $this->$attribute;};
return \Closure::bind($getter, $obj, get_class($obj));
}
}
$hydrated = new Hydrator();
$obj = new Foo();
$getter = $hydrated->getPrivate($obj, 'foo');
var_dump($getter());