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

preferences:
32.68 ms | 402 KiB | 5 Q