3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ParentClass { // whether it's abstract or not makes no difference public const TABLE = 'fallback_const_if_wanted'; public static string $table = 'fallback_var_if_wanted'; public static function demo() { echo 'self::TABLE is ', self::TABLE, "\n"; echo 'self::$table is ', self::$table, "\n"; echo 'static::TABLE is ', static::TABLE, "\n"; echo 'static::$table is ', static::$table, "\n"; } } class ChildClass extends ParentClass { public const TABLE = 'child_const'; public static string $table = 'child_var'; } ChildClass::demo();
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
self::TABLE is fallback_const_if_wanted self::$table is fallback_var_if_wanted static::TABLE is child_const static::$table is child_var

preferences:
69.68 ms | 406 KiB | 5 Q