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) { } public function setStatus(string $status): void { assert( in_array($status, [self::STATUS_ACTIVE, self::STATUS_INACTIVE]), sprintf('Le status %s n\'est pas valide. Les status possibles sont : %s', $status, implode(‘, ‘, [self::STATUS_ACTIVE, self::STATUS_INACTIVE])) ); $this->status = $status; } public function getStatus(): string { return $this->status; } } class Admin extends User { // Ajout d'un tableau de roles pour affiner les droits des administrateurs :) public function __construct(public string $username, public array $roles = [], public string $status = self::STATUS_ACTIVE) { } // Méthode d'ajout d'un rôle, puis on supprime les doublons avec array_filter. public function addRole(string $role): void { $this->roles[] = $role; $this->roles = array_filter($this->roles); } // Méthode de renvoie des rôles, dans lequel on définit le rôle ADMIN par défaut. public function getRoles(): array { $roles = $this->roles; $roles[] = 'ADMIN'; return $roles; } public function setRoles(array $roles): void { $this->roles = $roles; } }
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.65 ms | 405 KiB | 5 Q