3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private int $foo; function __construct(int $foo){ $this->foo = $foo; } function getFoo(): int{ return $this->foo; } } class Baz extends Foo { function __construct(){ // there, you broke encapsulation as you didn't call parent::__construct() // having fields typechecked after construction would actually enforce the call of base constructors } } (new Baz())->getFoo(); // rekt
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.14
Fatal error: Uncaught Error: Typed property Foo::$foo must not be accessed before initialization in /in/CqTIA:11 Stack trace: #0 /in/CqTIA(23): Foo->getFoo() #1 {main} thrown in /in/CqTIA on line 11
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/CqTIA on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting variable (T_VARIABLE) in /in/CqTIA on line 5
Process exited with code 255.

preferences:
64.92 ms | 409 KiB | 5 Q