3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public ?string $foo; public string $foobar; public ?string $bar = ''; } $vars = get_object_vars(new A); var_dump(assert(array_key_exists('bar', $vars)) ? 'bar exists in $vars' : 'bar does not exist in $vars'); var_dump(assert(array_key_exists('foobar', $vars)) ? 'foobar exists in $vars' : 'foobar does not exist in $vars'); var_dump(assert(array_key_exists('foo', $vars)) ? 'foo exists in $vars' : 'foo does not exist in $vars');
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
string(19) "bar exists in $vars" Fatal error: Uncaught AssertionError: assert(array_key_exists('foobar', $vars)) in /in/eg6o0:12 Stack trace: #0 /in/eg6o0(12): assert(false, 'assert(array_ke...') #1 {main} thrown in /in/eg6o0 on line 12
Process exited with code 255.
Output for 7.4.0 - 7.4.33
string(19) "bar exists in $vars" Warning: assert(): assert(array_key_exists('foobar', $vars)) failed in /in/eg6o0 on line 12 string(30) "foobar does not exist in $vars" Warning: assert(): assert(array_key_exists('foo', $vars)) failed in /in/eg6o0 on line 13 string(27) "foo does not exist in $vars"
Output for 7.1.26 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST) in /in/eg6o0 on line 4
Process exited with code 255.

preferences:
126.18 ms | 409 KiB | 5 Q