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));
No results found

preferences:
160.86 ms | 996 KiB | 7 Q