3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); error_reporting(E_ALL); final class foo { protected string $name; public function setName(string $name): void { if (!empty($this->name)) { throw new \RuntimeException('name already set and cannot be changed.'); } $this->name = $name; } public function getName(): string { return $this->name; } } $test1 = new foo(); var_dump($test1->getName());
Output for 8.1.34, 8.2.0 - 8.2.36, 8.3.0 - 8.3.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.12
Fatal error: Uncaught Error: Typed property foo::$name must not be accessed before initialization in /in/lU5Xt:20 Stack trace: #0 /in/lU5Xt(26): foo->getName() #1 {main} thrown in /in/lU5Xt on line 20
Process exited with code 255.

preferences:
36.8 ms | 1164 KiB | 6 Q