class My {
function __construct($arr) {
var_dump($arr);
}
}
$class = 'My';
$a = new $class([1,2]);
$obj = new TestableClass();
$reflection = new ReflectionClass($obj);
$privatProperty = $reflection->getProperty('privateProperty');
$privatProperty->setAccessible(true);
$privatProperty->setValue($obj, 'value');
foreach ($validatorAttrs as $validator_property_key => $validator_property_value) {
// Check the class of such properties.
try {
$reflection->getProperty($validator_property_key);
} catch (\ReflectionException $e) {
throw new \InvalidArgumentException(
get_class($this) . ": Bad call validator settings on property `$key`: ". $e->getMessage()
);
}
// Set properties validator specified by the customer.
$o->$validator_property_key = $validator_property_value;
}
Find more questions by tags PHP