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.13, 8.1rc1 - rc3
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.26
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/g4tlE on line 12
Process exited with code 255.

preferences:
34 ms | 461 KiB | 5 Q