3v4l.org

run code in 200+ PHP versions simultaneously
<?php class Foo { public bool $bool = false; public int $int = 0; public string $string = ''; public array $arry = []; public stdClass $obj; public function __construct($value) { try { $this->bool = $value; } catch (TypeError $e) {} try { $this->int = $value; } catch (TypeError $e) {} try { $this->string = $value; } catch (TypeError $e) {} try { $this->arry = $value; } catch (TypeError $e) {} try { $this->obj = $value; } catch (TypeError $e) {} } } var_export(new Foo(null)); echo PHP_EOL; var_export(new Foo(true)); echo PHP_EOL; var_export(new Foo(10)); echo PHP_EOL; var_export(new Foo('text string')); echo PHP_EOL; var_export(new Foo(array(1,2,3))); echo PHP_EOL;
based on Fg3uU
Output for 7.4.0alpha1 - 7.4.0rc2
Foo::__set_state(array( 'bool' => false, 'int' => 0, 'string' => '', 'arry' => array ( ), )) Foo::__set_state(array( 'bool' => true, 'int' => 1, 'string' => '1', 'arry' => array ( ), )) Foo::__set_state(array( 'bool' => true, 'int' => 10, 'string' => '10', 'arry' => array ( ), )) Foo::__set_state(array( 'bool' => true, 'int' => 0, 'string' => 'text string', 'arry' => array ( ), )) Foo::__set_state(array( 'bool' => false, 'int' => 0, 'string' => '', 'arry' => array ( 0 => 1, 1 => 2, 2 => 3, ), ))
Output for 7.1.25 - 7.3.10
Parse error: syntax error, unexpected 'bool' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/0e6Co on line 4
Process exited with code 255.