3v4l.org

run code in 300+ PHP versions simultaneously
<?php // overriding an untyped parent constant with a typed one class A { public const VALUE = 42; // untyped } class B extends A { public const float VALUE = 42.5; // narrowing to `float` } echo "Parent type: " . gettype(A::VALUE) . "\n"; echo "Child value: " . B::VALUE . "\n";
Output for 8.3.0 - 8.3.26, 8.4.1 - 8.4.14
Parent type: integer Child value: 42.5
Output for 8.2.0 - 8.2.29
Parse error: syntax error, unexpected identifier "VALUE", expecting "=" in /in/MUm1l on line 10
Process exited with code 255.

preferences:
55.9 ms | 407 KiB | 5 Q