3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Duplicates an array, even if the array contains * references. * * @param $arr array The array to duplicate. * @return array The duplicate of the array. */ function array_dup($arr) { $ret = []; foreach ($arr as $key => $value) $ret[$key] = $value; return $ret; } /** * Create an array of references to the elements of an array. * * @param $arr array The array to create references to. * @return array */ function refArray(&$arr) { $refs = []; foreach ($arr as $key => $value) $refs[$key] = &$arr[$key]; return $refs; } /** * Invokes a callback while capturing the output buffer * changes produced by it, and returns those changes as * a string. * * @param $callback callback The function to call. * @return string */ function captureOutputBuffer($callback) { ob_start(); $callback(); $dat = ob_get_contents(); if ($dat === false || ob_end_clean() !== true) throw new LogicException('ERROR: Something is wrong! Failed to retrieve the buffer\'s body!'); return $dat; } /** * Clean a partial page path of all invalid characters, * and ready it for lookup in the database. * * @param $path string The path to clean. * @return string A clean version of the path. */ function cleanPagePath($path) { $path = strtolower(rtrim($path, '/')); $tmp = ''; $pathLength = strlen($path); for ($i = 0; $i < $pathLength; $i++) { switch ($path[$i]) { case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '_': case '-': case '/': $tmp .= $path[$i]; continue; // Backslashes are looked up as forward slashes. case '\\': $tmp .= '/'; continue; // Spaces are replaced with underscores. case ' ': $tmp .= '_'; continue; default: continue; } } return $tmp; }
Output for 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.6
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/LT8lL on line 106 Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/LT8lL on line 111 Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/LT8lL on line 116 Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/LT8lL on line 119
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/LT8lL on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/LT8lL on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/LT8lL on line 12
Process exited with code 255.

preferences:
225.68 ms | 401 KiB | 329 Q