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 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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.
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 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.
Output for 5.6.0 - 5.6.40
Fatal error: Uncaught exception 'Exception' with message '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.

preferences:
225.49 ms | 401 KiB | 300 Q