3v4l.org

run code in 300+ PHP versions simultaneously
<?php class T { } class X { public function __construct(T $t) { $this->t = $t; } } class Builder { /** * @var T|null */ public $t; public function createX(): X { $this->validate(); // PHPStan complains that at this line, $this->t could be null, except we've already checked it isn't... // Parameter #1 $t of class X constructor expects T, T|null given. return new X($this->t); } private function validate() { if (is_null($this->t)) { throw new \Exception; } } } $builder = new Builder; $builder->t = new T; $builder->createX();
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Deprecated: Creation of dynamic property X::$t is deprecated in /in/WkL0Y on line 7
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Creation of dynamic property X::$t is deprecated in /in/WkL0Y on line 7
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28

preferences:
206.88 ms | 403 KiB | 165 Q