3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_val_as_array($val) { $type = gettype($val); echo "accessing $type as array {$val['test']}\n"; $val['test'] = 'wtf'; echo "set $type offset test to string wtf\n"; echo "accessing $type offset test {$val['test']}\n"; echo "val = ".var_export($val, true)."\n"; }; test_val_as_array(null); test_val_as_array('test'); test_val_as_array(123);
Output for 8.3.0 - 8.3.7
Warning: Trying to access array offset on null in /in/BGiQU on line 5 accessing NULL as array set NULL offset test to string wtf accessing NULL offset test wtf val = array ( 'test' => 'wtf', ) Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/BGiQU:5 Stack trace: #0 /in/BGiQU(13): test_val_as_array('test') #1 {main} thrown in /in/BGiQU on line 5
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: Trying to access array offset on value of type null in /in/BGiQU on line 5 accessing NULL as array set NULL offset test to string wtf accessing NULL offset test wtf val = array ( 'test' => 'wtf', ) Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/BGiQU:5 Stack trace: #0 /in/BGiQU(13): test_val_as_array('test') #1 {main} thrown in /in/BGiQU on line 5
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Notice: Trying to access array offset on value of type null in /in/BGiQU on line 5 accessing NULL as array set NULL offset test to string wtf accessing NULL offset test wtf val = array ( 'test' => 'wtf', ) Warning: Illegal string offset 'test' in /in/BGiQU on line 5 accessing string as array t Warning: Illegal string offset 'test' in /in/BGiQU on line 6 set string offset test to string wtf Warning: Illegal string offset 'test' in /in/BGiQU on line 8 accessing string offset test w val = 'west' Notice: Trying to access array offset on value of type int in /in/BGiQU on line 5 accessing integer as array Warning: Cannot use a scalar value as an array in /in/BGiQU on line 6 set integer offset test to string wtf Notice: Trying to access array offset on value of type int in /in/BGiQU on line 8 accessing integer offset test val = 123
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
accessing NULL as array set NULL offset test to string wtf accessing NULL offset test wtf val = array ( 'test' => 'wtf', ) Warning: Illegal string offset 'test' in /in/BGiQU on line 5 accessing string as array t Warning: Illegal string offset 'test' in /in/BGiQU on line 6 set string offset test to string wtf Warning: Illegal string offset 'test' in /in/BGiQU on line 8 accessing string offset test w val = 'west' accessing integer as array Warning: Cannot use a scalar value as an array in /in/BGiQU on line 6 set integer offset test to string wtf accessing integer offset test val = 123

preferences:
211.7 ms | 404 KiB | 256 Q