class Configurable
{
protected function configure(array $config): void
{
foreach ($config as $key => $value){
if (property_exists($this, $key)){
$this->{$key} = $value;
}
}
}
}
class C extends Configurable
{
private $abc;
public function __construct()
{
$this->configure(['abc' => 5]);
}
}
$c = new C();
This code gives me error Cannot access private property C::$abc
It is obvious when private variable in parent class but in this code the private variable is in child class and property_exists sees this variable. I can not find explanation in php docs.
My confusion is as follows.
Parent method is inherited in child. My assumption is that this method should have access to variable in child, but it does not have. property_exists knows about this property, but can not set it.