3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class Admin { private const STATUS_ACTIVE = 'active'; private const STATUS_INACTIVE = 'inactive'; // Ajout d'un tableau de roles pour affiner les droits des administrateurs :) public function __construct(public string $username, private array $roles = [], private 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; } // 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éfini le role ADMIN par défaut. public function getRoles(): array { $roles = $this->roles; $roles[] = 'ADMIN'; return $roles; } public function setRoles(array $roles): void { $this->roles = $roles; } } $a = new Admin('Bobby'); var_dump($a);
Output for git.master, git.master_jit, rfc.property-hooks
object(Admin)#1 (3) { ["username"]=> string(5) "Bobby" ["roles":"Admin":private]=> array(0) { } ["status":"Admin":private]=> string(6) "active" }

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.68 ms | 405 KiB | 5 Q