3v4l.org

run code in 300+ PHP versions simultaneously
<?php function closure_to_str($func) { $refl = new \ReflectionFunction($func); // get reflection object $path = $refl->getFileName(); // absolute path of php file $begn = $refl->getStartLine(); // have to `-1` for array index $endn = $refl->getEndLine(); $dlim = "\n"; // or PHP_EOL $list = explode($dlim, file_get_contents($path)); // lines of php-file source $list = array_slice($list, ($begn-1), ($endn-($begn-1))); // lines of closure definition $last = (count($list)-1); // last line number if((substr_count($list[0],'function')>1)|| (substr_count($list[0],'{')>1) || (substr_count($list[$last],'}')>1)) { throw new \Exception("Too complex context definition in: `$path`. Check lines: $begn & $endn."); } $list[0] = ('function'.explode('function',$list[0])[1]); $list[$last] = (explode('}',$list[$last])[0].'}'); return implode($list,$dlim); } $dog2 = ['bark'=>function($foo = '{'){}]; echo closure_to_str($dog2['bark'])."\n\n";
Output for git.master_jit, git.master, rfc.property-hooks
Fatal error: Uncaught Exception: Too complex context definition in: `/in/CEmqV`. Check lines: 23 & 23. in /in/CEmqV:15 Stack trace: #0 /in/CEmqV(25): closure_to_str(Object(Closure)) #1 {main} thrown in /in/CEmqV on line 15
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.85 ms | 401 KiB | 8 Q