3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class User { public const STATUS_ACTIVE = 'active'; public const STATUS_INACTIVE = 'inactive'; public static $nombreUtilisateursInitialisés = 0; public function __construct(public string $username, public string $status = self::STATUS_ACTIVE) { } } class Admin extends User { public static $nombreAdminInitialisés = 0; public static function nouvelleInitialisation() { self::$nombreAdminInitialisés++; parent::$nombreUtilisateursInitialisés++; } } Admin::nouvelleInitialisation(); var_dump(Admin::$nombreAdminInitialisés, Admin::$nombreUtilisateursInitialisés, User::$nombreUtilisateursInitialisés); var_dump(User::$nombreAdminInitialisés); // ceci ne marche pas.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
int(1) int(1) int(1) Fatal error: Uncaught Error: Access to undeclared static property User::$nombreAdminInitialisés in /in/g4tlE:32 Stack trace: #0 {main} thrown in /in/g4tlE on line 32
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/g4tlE on line 12
Process exited with code 255.

preferences:
75.08 ms | 407 KiB | 5 Q