3v4l.org

run code in 500+ PHP versions simultaneously
<?php trait Foo { private function sayHello() { echo "Hello!" . PHP_EOL; } } class Bar { use Foo; public function welcome() { return $this->sayHello(); } } class Baz extends Bar { public function welcome() { return $this->sayHello(); } } $bar = new Bar; $baz = new Baz; $bar->welcome(); $baz->welcome();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Hello! Fatal error: Uncaught Error: Call to private method Bar::sayHello() from scope Baz in /in/keT0W:22 Stack trace: #0 /in/keT0W(29): Baz->welcome() #1 {main} thrown in /in/keT0W on line 22
Process exited with code 255.
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Hello! Fatal error: Uncaught Error: Call to private method Bar::sayHello() from context 'Baz' in /in/keT0W:22 Stack trace: #0 /in/keT0W(29): Baz->welcome() #1 {main} thrown in /in/keT0W on line 22
Process exited with code 255.

preferences:
105.96 ms | 1536 KiB | 4 Q