3v4l.org

run code in 300+ 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)); var_export(new Foo(true)); var_export(new Foo(10)); var_export(new Foo('text string')); var_export(new Foo(array(1,2,3)));
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
\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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 \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.4.4 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
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.1.32, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'bool' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/Fg3uU on line 4
Process exited with code 255.

preferences:
160.68 ms | 402 KiB | 175 Q