3v4l.org

run code in 300+ PHP versions simultaneously
<?php class stdobject { public function __call($method, $arguments) { if (isset($this->{$method}) && is_callable($this->{$method})) { return call_user_func_array($this->{$method}, $arguments); } else { throw new Exception("Fatal error: Call to undefined method: $method"); } } } $mod = function() { $self = new stdobject(); $self->init = function ($params) use ($self) { $self->_opmode = &$params['opmode']; }; $self->setup = function () use ($self) { $self->_opmode = 'dog'; }; $self->print = function () use ($self) { echo $self->_opmode . "\n"; }; return $self; }; $obj = $mod(); $reference = 'fish'; $obj->init(['opmode' => &$reference]); $obj->print(); // fish $obj->setup(); $obj->print(); // dog $reference = 'cats'; $obj->print(); // cats
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Creation of dynamic property stdobject::$init is deprecated in /in/SLAri on line 16 Deprecated: Creation of dynamic property stdobject::$setup is deprecated in /in/SLAri on line 20 Deprecated: Creation of dynamic property stdobject::$print is deprecated in /in/SLAri on line 24 Deprecated: Creation of dynamic property stdobject::$_opmode is deprecated in /in/SLAri on line 17 fish dog cats
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 Deprecated: Creation of dynamic property stdobject::$init is deprecated in /in/SLAri on line 16 Deprecated: Creation of dynamic property stdobject::$setup is deprecated in /in/SLAri on line 20 Deprecated: Creation of dynamic property stdobject::$print is deprecated in /in/SLAri on line 24 Deprecated: Creation of dynamic property stdobject::$_opmode is deprecated in /in/SLAri on line 17 fish dog cats
Output for 5.6.0 - 5.6.40, 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
fish dog cats

preferences:
226.66 ms | 403 KiB | 291 Q