3v4l.org

run code in 300+ PHP versions simultaneously
<?php class B { function va2() { return 22; } public $v3=19; function __construct() { $this->va = function() { return []; }; } } $o=new B; var_dump(($o->va)()); //var_dump(($o['va'])()); var_dump($o['va']());
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Creation of dynamic property B::$va is deprecated in /in/2RuQX on line 11 array(0) { } Fatal error: Uncaught Error: Cannot use object of type B as array in /in/2RuQX:20 Stack trace: #0 {main} thrown in /in/2RuQX on line 20
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
array(0) { } Fatal error: Uncaught Error: Cannot use object of type B as array in /in/2RuQX:20 Stack trace: #0 {main} thrown in /in/2RuQX on line 20
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Parse error: syntax error, unexpected '(' in /in/2RuQX on line 18
Process exited with code 255.

preferences:
220.54 ms | 402 KiB | 322 Q