3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class Foo { public function __construct( public int $baz { set (int|string|stdClass $value) { if (is_int($value)) { $this->baz = $value; } else if ($value instanceof stdClass && property_exists($value, 'baz') && is_int($value->baz) ) { $this->baz = $value->baz; } else if (is_numeric($value)) { $this->baz = (int) $value; } else { throw new InvalidArgumentException('Invalid value'); } } }, ) {} } $obj = new stdClass(); $obj->baz = 123; var_dump(new Foo($obj));
Output for git.master_jit
Fatal error: Uncaught TypeError: Foo::__construct(): Argument #1 ($baz) must be of type int, stdClass given, called in /in/pPhVH on line 28 and defined in /in/pPhVH:7 Stack trace: #0 /in/pPhVH(28): Foo->__construct(Object(stdClass)) #1 {main} thrown in /in/pPhVH on line 7
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:
146.9 ms | 999 KiB | 7 Q