<?php
declare(strict_types=1);
class User
{
public const STATUS_ACTIVE = 'active';
public const STATUS_INACTIVE = 'inactive';
public function __construct(public string $username, public string $status = self::STATUS_ACTIVE)
{
}
}
class Admin extends User
{
// ...
public function printStatus()
{
// vous pouvez accéder au status comme si la propriété appartenait à Admin :)
echo $this->status;
}
}
$admin = new Admin('Lily');
$admin->printStatus();
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/ibKU5 on line 10
Process exited with code 255.
Output for 7.0.15 - 7.0.33
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/ibKU5 on line 7
Process exited with code 255.
Output for 5.5.18
Warning: Unsupported declare 'strict_types' in /in/ibKU5 on line 3
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/ibKU5 on line 7
Process exited with code 255.
Output for 4.3.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ibKU5 on line 7
Process exited with code 255.