3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class A { protected const c = null; abstract protected static function fs(); abstract protected function f(); } class B extends A { public function __construct(C $c) { var_dump(C::fs()); var_dump($c->f()); var_dump(C::C); } protected static function fs() {} protected function f() {} } class C extends A { protected const C = 'C::C'; protected static function fs() { return __METHOD__; } protected function f() { return __METHOD__; } } new B(new C);
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.4, 8.3.6
string(5) "C::fs" string(4) "C::f" Fatal error: Uncaught Error: Cannot access protected constant C::C in /in/2lU3i:15 Stack trace: #0 /in/2lU3i(33): B->__construct(Object(C)) #1 {main} thrown in /in/2lU3i on line 15
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(5) "C::fs" string(4) "C::f" Fatal error: Uncaught Error: Cannot access protected constant C::C in /in/2lU3i:15 Stack trace: #0 /in/2lU3i(33): B->__construct(Object(C)) #1 {main} thrown in /in/2lU3i on line 15
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
string(5) "C::fs" string(4) "C::f" Fatal error: Uncaught Error: Cannot access protected const C::C in /in/2lU3i:15 Stack trace: #0 /in/2lU3i(33): B->__construct(Object(C)) #1 {main} thrown in /in/2lU3i on line 15
Process exited with code 255.
Output for 7.0.0 - 7.0.25
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/2lU3i on line 4
Process exited with code 255.

preferences:
220.43 ms | 401 KiB | 226 Q