3v4l.org

run code in 300+ PHP versions simultaneously
<?php class C { public string $a; public string $b; public function __construct($a, $b) { $this->a = $a; $this->b = $b; } } // test only a $c = new C("foo", null); var_dump($c->a === "foo"); // test only b $c = new C(null, "foo"); var_dump($c->b === "foo"); ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: Cannot assign null to property C::$b of type string in /in/EKk50:7 Stack trace: #0 /in/EKk50(12): C->__construct('foo', NULL) #1 {main} thrown in /in/EKk50 on line 7
Process exited with code 255.
Output for 7.4.3 - 7.4.33
Fatal error: Uncaught TypeError: Typed property C::$b must be string, null used in /in/EKk50:7 Stack trace: #0 /in/EKk50(12): C->__construct('foo', NULL) #1 {main} thrown in /in/EKk50 on line 7
Process exited with code 255.
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33
Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/EKk50 on line 3
Process exited with code 255.
Output for 5.4.0 - 5.4.11
Parse error: syntax error, unexpected 'string' (T_STRING), expecting variable (T_VARIABLE) in /in/EKk50 on line 3
Process exited with code 255.
Output for 5.3.0 - 5.3.21
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/EKk50 on line 3
Process exited with code 255.

preferences:
158.9 ms | 401 KiB | 174 Q