3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.4.0 - 7.2.0
Output for 4.4.2 - 4.4.9, 5.1.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.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.