3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { function __get($p) { var_dump(array('get', $p)); return 2000; } function __set($p, $v) { var_dump(array('set', $p, $v)); } } $x = new A(); var_dump(array('get blah', $x->blah)); var_dump(array('set blah', $x->blah = 4444)); var_dump(array('get array blah', $x['blah'])); var_dump(array('set array blah', $x['blah'] = 4444));
based on jRfMn
Output for 7.0.0 - 7.2.0
array(2) { [0]=> string(3) "get" [1]=> string(4) "blah" } array(2) { [0]=> string(8) "get blah" [1]=> int(2000) } array(3) { [0]=> string(3) "set" [1]=> string(4) "blah" [2]=> int(4444) } array(2) { [0]=> string(8) "set blah" [1]=> int(4444) } Fatal error: Uncaught Error: Cannot use object of type A as array in /in/YgnnO:18 Stack trace: #0 {main} thrown in /in/YgnnO on line 18
Process exited with code 255.
Output for 5.0.0 - 5.6.28
array(2) { [0]=> string(3) "get" [1]=> string(4) "blah" } array(2) { [0]=> string(8) "get blah" [1]=> int(2000) } array(3) { [0]=> string(3) "set" [1]=> string(4) "blah" [2]=> int(4444) } array(2) { [0]=> string(8) "set blah" [1]=> int(4444) } Fatal error: Cannot use object of type A as array in /in/YgnnO on line 18
Process exited with code 255.
Output for 4.3.0 - 4.4.9
Notice: Undefined property: blah in /in/YgnnO on line 16 array(2) { [0]=> string(8) "get blah" [1]=> NULL } array(2) { [0]=> string(8) "set blah" [1]=> int(4444) } array(2) { [0]=> string(14) "get array blah" [1]=> NULL } Warning: Cannot use a scalar value as an array in /in/YgnnO on line 19 array(2) { [0]=> string(14) "set array blah" [1]=> NULL }