3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { protected $foo; public function __construct($foo) { $this->foo = $foo; } protected function bar() { echo 'Accessed the protectd method.'; } } class Test2 { public function baz(Test $other) { // We can change the protected property: $other->foo = 'hello'; var_dump($other->foo); // We can also call the protected method: $other->bar(); } } $test = new Test2('test'); $test->baz(new Test('other'));

preferences:
32.72 ms | 402 KiB | 5 Q