3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_val_as_array($val) { $type = gettype($val); try { echo "val before access = ".var_export($val, true)."\n"; echo "accessing $type as array {$val['test']}\n"; $val['test'] = 'wtf'; echo "set $type offset 'test' to string 'wtf'\n"; echo "$type offset 'test' = {$val['test']}\n"; echo "val after access = ".var_export($val, true)."\n"; } catch (Exception $e) { echo "caught error {$e->getMessage()} when accessing $type as array\n"; } }; test_val_as_array(null); test_val_as_array('test'); test_val_as_array(123); test_val_as_array(true); test_val_as_array(1.2); test_val_as_array(new stdClass);
Output for git.master, git.master_jit
val before access = NULL Warning: Trying to access array offset on value of type null in /in/A7gEa on line 7 accessing NULL as array set NULL offset 'test' to string 'wtf' NULL offset 'test' = wtf val after access = array ( 'test' => 'wtf', ) val before access = 'test' Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/A7gEa:7 Stack trace: #0 /in/A7gEa(18): test_val_as_array('test') #1 {main} thrown in /in/A7gEa on line 7
Process exited with code 255.
Output for rfc.property-hooks
val before access = NULL Warning: Trying to access array offset on null in /in/A7gEa on line 7 accessing NULL as array set NULL offset 'test' to string 'wtf' NULL offset 'test' = wtf val after access = array ( 'test' => 'wtf', ) val before access = 'test' Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/A7gEa:7 Stack trace: #0 /in/A7gEa(18): test_val_as_array('test') #1 {main} thrown in /in/A7gEa on line 7
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
50.01 ms | 401 KiB | 8 Q