<?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.
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.