3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function testIsCallable(callable $param) { return is_callable($param); } private function privateMethod() { echo "This is a private method"; } public function test($param) { if ($this->testIsCallable($param)) { $param(); } } } class B extends A { public function test($param) { if ($this->testIsCallable($param)) { $param(); } } } $a = new A(); $b = new B(); $callable = [$a, 'privateMethod']; $a->test($callable); $b->test($callable);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
This is a private method Fatal error: Uncaught Error: Call to private method A::privateMethod() from scope B in /in/qlsrm:24 Stack trace: #0 /in/qlsrm(35): B->test(Array) #1 {main} thrown in /in/qlsrm on line 24
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
This is a private method Fatal error: Uncaught Error: Call to private method A::privateMethod() from context 'B' in /in/qlsrm:24 Stack trace: #0 /in/qlsrm(35): B->test(Array) #1 {main} thrown in /in/qlsrm on line 24
Process exited with code 255.
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
This is a private method Fatal error: Call to private method A::privateMethod() from context 'B' in /in/qlsrm on line 24
Process exited with code 255.

preferences:
151.03 ms | 402 KiB | 226 Q