3v4l.org

run code in 300+ PHP versions simultaneously
<?php Class World { public $greeting; public $rand; // no value private $priv; public function __construct() { $this->greeting = 'Hello'; } } $w = new World(); $wr = (array) $w; list($greet_exists, $greet_isset_o, $greet_isset_a, $greet_a_e,$greet_empty) = [ json_encode(property_exists($w,'greeting')), json_encode(isset($w->greeting)), json_encode(isset($wr['greeting'])), json_encode(array_key_exists('greeting', $wr)), json_encode(empty($w->greeting)) ]; echo "Greeting: {$wr['greeting']}; Exists: $greet_exists; Is prop set: $greet_isset_o; Is index set: $greet_isset_a; Array index: $greet_a_e; Empty: $greet_empty".PHP_EOL; list($rand_exists,$rand_isset_o,$rand_isset_a,$rand_a_e,$rand_empty) = [ json_encode(property_exists($w,'rand')),json_encode(isset($w->rand)), json_encode(isset($wr['rand'])),json_encode(array_key_exists('rand', $wr)), json_encode(empty($w->rand)) ]; echo "Random: {$wr['rand']}; Exists: $rand_exists; Is prop set: $rand_isset_o; Is index set: $rand_isset_a; Array index: $rand_a_e; Empty: $rand_empty".PHP_EOL; list($priv_exists,$priv_isset_o,$priv_isset_a,$priv_a_e,$priv_empty) = [ json_encode(property_exists($w,'priv')),json_encode(isset($w->priv)), json_encode(isset($wr['priv'])),json_encode(array_key_exists('priv', $wr)), json_encode(empty($w->priv)) ]; echo "Private: {$wr['priv']}; Exists: $priv_exists; Is prop set: $priv_isset_o; Is index set: $priv_isset_a; Array index: $priv_a_e; Empty: $priv_empty".PHP_EOL;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Greeting: Hello; Exists: true; Is prop set: true; Is index set: true; Array index: true; Empty: false Random: ; Exists: true; Is prop set: false; Is index set: false; Array index: true; Empty: true Warning: Undefined array key "priv" in /in/1hLkj on line 31 Private: ; Exists: true; Is prop set: false; Is index set: false; Array index: false; Empty: true
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 Greeting: Hello; Exists: true; Is prop set: true; Is index set: true; Array index: true; Empty: false Random: ; Exists: true; Is prop set: false; Is index set: false; Array index: true; Empty: true Warning: Undefined array key "priv" in /in/1hLkj on line 31 Private: ; Exists: true; Is prop set: false; Is index set: false; Array index: false; Empty: true
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Greeting: Hello; Exists: true; Is prop set: true; Is index set: true; Array index: true; Empty: false Random: ; Exists: true; Is prop set: false; Is index set: false; Array index: true; Empty: true Notice: Undefined index: priv in /in/1hLkj on line 31 Private: ; Exists: true; Is prop set: false; Is index set: false; Array index: false; Empty: true
Output for 7.3.32 - 7.3.33
Greeting: Hello; Exists: true; Is prop set: true; Is index set: true; Array index: true; Empty: false Random: ; Exists: true; Is prop set: false; Is index set: false; Array index: true; Empty: true Private: ; Exists: true; Is prop set: false; Is index set: false; Array index: false; Empty: true

preferences:
164.34 ms | 402 KiB | 172 Q