3v4l.org

run code in 300+ PHP versions simultaneously
<?php readonly class FormattedString { private string $value; private function __construct (string $str) { $this->value = $str; } public static function create (string $str): self|NotValidFormattedString { $matches = null; preg_match("/[a-z]{2}-[a-z]{2}-[a-z]{8}-[a-z]{1}/", $str, $matches); if (count($matches) === 0) { return new NotValidFormattedString($str, "poshel nahoi suka, chto za govno ti mne peredal, blyad"); } return new self($str); } } readonly class NotValidFormattedString { public function __construct (public string $str, public string $err) {} } class ValidateFormattedString { public function __invoke(string $str): FormattedString|NotValidFormattedString { return FormattedString::create($str); } } class SuperYellowCircle { public function __construct (public FormattedString $toChtoVMoemPrimereByloClassomYoba) {} } $stringOne = (new ValidateFormattedString)("aa-bb-cccccccc-d"); $circleOne = new SuperYellowCircle($stringOne); var_dump($circleOne); $stringTwo = (new ValidateFormattedString)("butthurt"); $circleTwo = new SuperYellowCircle($stringTwo); var_dump($circleTwo);
Output for git.master, git.master_jit
object(SuperYellowCircle)#1 (1) { ["toChtoVMoemPrimereByloClassomYoba"]=> object(FormattedString)#2 (1) { ["value":"FormattedString":private]=> string(16) "aa-bb-cccccccc-d" } } Fatal error: Uncaught TypeError: SuperYellowCircle::__construct(): Argument #1 ($toChtoVMoemPrimereByloClassomYoba) must be of type FormattedString, NotValidFormattedString given, called in /in/pJbBI on line 40 and defined in /in/pJbBI:32 Stack trace: #0 /in/pJbBI(40): SuperYellowCircle->__construct(Object(NotValidFormattedString)) #1 {main} thrown in /in/pJbBI on line 32
Process exited with code 255.

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:
44.46 ms | 406 KiB | 5 Q