- var_dump: documentation ( source)
<?php
class Hoge {
private $a = 'foo';
private $b = 'bar';
}
function updateProperties($instance, array $properties) {
$ref = new ReflectionClass($instance);
$props = $ref->getProperties(ReflectionProperty::IS_PRIVATE);
foreach ($props as $prop) {
if (isset($properties[$prop->name])) {
$prop->setAccessible(true);
$prop->setValue($properties[$prop->name]);
}
}
}
$h = new Hoge;
updateProperties($h, array('a' => 'fizz', 'b' => 'buzz'));
var_dump($h);