3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); namespace App { class Status { const ACTIVE = 1; const INACTIVE = 2; const SOLD = 3; private $value; private $labels = [ self::ACTIVE => 'Active', self::INACTIVE => 'Inactive', self::SOLD => 'Sold', ]; /** * Status constructor. * @param $value */ public function __construct(int $value) { if (!in_array($value, array_keys($this->labels))) { throw new \InvalidArgumentException('Invalid status'); } $this->value = $value; } public function __toString() { return $this->labels[$this->value]; } } class Product { private $id; private $name; private $status; /** * Product constructor. * @param $id * @param $name * @param $status */ public function __construct(int $id, string $name, Status $status) { $this->id = $id; $this->name = $name; $this->status = $status; } } $status = new Status(Status::SOLD); var_dump(new Product(1, 'Chess board', $status)); echo "\n\n\n\n{$status}"; }
Output for git.master, git.master_jit, rfc.property-hooks
object(App\Product)#2 (3) { ["id":"App\Product":private]=> int(1) ["name":"App\Product":private]=> string(11) "Chess board" ["status":"App\Product":private]=> object(App\Status)#1 (2) { ["value":"App\Status":private]=> int(3) ["labels":"App\Status":private]=> array(3) { [1]=> string(6) "Active" [2]=> string(8) "Inactive" [3]=> string(4) "Sold" } } } Sold

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:
42.23 ms | 402 KiB | 8 Q