3v4l.org

run code in 500+ PHP versions simultaneously
<?php class A { private static int $a = 6; private static function foo(): int { return 5; } public function run(): void { var_dump($this->foo()); var_dump($this::foo()); var_dump(static::foo()); echo "\n-----------\n"; var_dump($this::$a); var_dump(static::$a); echo "\n-----------\n"; $other = new static(); var_dump($other->foo()); var_dump($other::foo()); } } class B extends A { public static string $a = 'b'; public static function foo(): string { return "a"; } } (new B)->run();
Output for 8.1.28 - 8.1.34, 8.2.16 - 8.2.30, 8.3.3 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
int(5) string(1) "a" string(1) "a" ----------- string(1) "b" string(1) "b" ----------- int(5) string(1) "a"

preferences:
59.15 ms | 795 KiB | 4 Q