<?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);
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.