3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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() { $test = new stdobject(); $opmode=null; $mode='somemode'; $ref2=&$mode; $test->init = function ($params) use (&$opmode) { $opmode = &$params['opmode']; }; $test->setup = function () use (&$opmode,&$mode) { $opmode = 'test'; $mode='someothermode'; }; $test->print=function() use (&$opmode,&$mode){ echo $opmode; echo $mode; }; return $test; }; $test = $mod(); $opmode = 'helloworld'; $test->init(['opmode' => &$opmode]); $test->setup(); $test->print(); echo $opmode;
based on WoK3G
Output for 5.6.0 - 7.3.0beta1
testsomeothermodehelloworld