<?php
class A {
public function myEcho($property)
{
echo $this->{$property} . PHP_EOL;
}
}
class B extends A
{
private $private;
protected $protected;
public function set($property, $value)
{
$this->{$property} = $value;
}
}
$b = new B();
$b->set('protected', 'test');
$b->myEcho('protected');
$b->set('private', 'test private');
$b->myEcho('private');
test
Fatal error: Uncaught Error: Cannot access private property B::$private in /in/elofK:8
Stack trace:
#0 /in/elofK(29): A->myEcho('private')
#1 {main}
thrown in /in/elofK on line 8
Process exited with code 255.