3v4l.org

run code in 300+ PHP versions simultaneously
<?php $A = new class() { private $name; function __construct(string $name) { $this->name = $name; } public function getName() : string { return $this->name; } }; $B = new $A('Matti'); $C = new $A('Pekka'); var_dump($B === $C);
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, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function class@anonymous::__construct(), 0 passed in /in/Z26WH on line 3 and exactly 1 expected in /in/Z26WH:6 Stack trace: #0 /in/Z26WH(3): class@anonymous->__construct() #1 {main} thrown in /in/Z26WH on line 6
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Fatal error: Uncaught TypeError: Argument 1 passed to class@anonymous::__construct() must be of the type string, none given, called in /in/Z26WH on line 3 and defined in /in/Z26WH:6 Stack trace: #0 /in/Z26WH(3): class@anonymous->__construct() #1 {main} thrown in /in/Z26WH on line 6
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/Z26WH on line 3
Process exited with code 255.

preferences:
147.11 ms | 402 KiB | 183 Q