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 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();
Output for 8.0.0 - 8.0.13, 8.1rc1 - rc3
active
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/ibKU5 on line 10
Process exited with code 255.

preferences:
42.54 ms | 528 KiB | 12 Q