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 private method.'; } } class Test2 { public function baz(Test $other) { // We can change the private property: $other->foo = 'hello'; var_dump($other->foo); // We can also call the private method: $other->bar(); } } $test = new Test2('test'); $test->baz(new Test('other'));

preferences:
49.78 ms | 402 KiB | 5 Q