3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace App; spl_autoload_register(function (string $name): void { printf("autoload: %s\n", $name); }); use stdClass; use Lib\Bar; final class Foo { public C1 $c1; public function method(C2 $c2) {} } $foo = new Foo(); try { $foo->c1 = new stdClass(); } catch (\Throwable $e) { // TypeError にはなるがオートローダは実行されない var_dump($e->getMessage()); } try { $foo->method(new stdClass()); } catch (\Throwable $e) { // TypeError にはなるがオートローダは実行されない var_dump($e->getMessage()); } var_dump(C3::class); var_dump($foo instanceOf C4);
Output for 8.1.0 - 8.1.29, 8.2.0 - 8.2.21, 8.3.0 - 8.3.9
string(62) "Cannot assign stdClass to property App\Foo::$c1 of type App\C1" string(107) "App\Foo::method(): Argument #1 ($c2) must be of type App\C2, stdClass given, called in /in/MtoWM on line 28" string(6) "App\C3" bool(false)

preferences:
47.59 ms | 403 KiB | 67 Q