@ 2019-10-10T04:28:38Z <?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;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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.0 - 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.0 - 7.1.33 , 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/0e6Co on line 4
Process exited with code 255 . preferences:dark mode live preview
183.36 ms | 402 KiB | 209 Q