3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private function foo() { echo "success!\n"; } public function test() { $this->foo(); static::foo(); } } class B extends A { /* foo() will be copied to B, hence its scope will still be A and * the call be successful */ } class C extends A { private function foo() { /* original method is replaced; the scope of the new one is C */ } } $b = new B(); $b->test(); $c = new C(); $c->test(); //fails ?>
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
success! success! success! Fatal error: Uncaught Error: Call to private method C::foo() from scope A in /in/vLnut:8 Stack trace: #0 /in/vLnut(26): A->test() #1 {main} thrown in /in/vLnut on line 8
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
success! success! success! Fatal error: Uncaught Error: Call to private method C::foo() from context 'A' in /in/vLnut:8 Stack trace: #0 /in/vLnut(26): A->test() #1 {main} thrown in /in/vLnut on line 8
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
success! success! success! Fatal error: Call to private method C::foo() from context 'A' in /in/vLnut on line 8
Process exited with code 255.
Output for 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/vLnut on line 3
Process exited with code 255.

preferences:
291.36 ms | 401 KiB | 416 Q