3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); class parent_ { public function __construct(){ } public static function createNew(): static{ return new static(); } } class child extends parent_ { public function __construct(int $a){ echo $a; } } child::createNew();
Output for 8.0.0, 8.1.23 - 8.1.34, 8.2.10 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught ArgumentCountError: Too few arguments to function child::__construct(), 0 passed in /in/cG5Am on line 10 and exactly 1 expected in /in/cG5Am:16 Stack trace: #0 /in/cG5Am(10): child->__construct() #1 /in/cG5Am(21): parent_::createNew() #2 {main} thrown in /in/cG5Am on line 16
Process exited with code 255.
Output for 7.3.0 - 7.3.26, 7.4.0 - 7.4.14
Parse error: syntax error, unexpected 'static' (T_STATIC) in /in/cG5Am on line 9
Process exited with code 255.

preferences:
77.79 ms | 1053 KiB | 4 Q