3v4l.org

run code in 300+ PHP versions simultaneously
<?php class __Utils { public static function setHeader(string $header, $variable, $replace = false, $httpresponse = null) { if($httpresponse !== null) { header("$header: $variable", $replace, $httpresponse); } else { header("$header: $variable", $replace); } } public static function setHeaders(array $headers) { foreach($headers as $header => $variables){ if(is_array($variables)) { $replace = (isset($variables[1]) && self::isBoolean($variables[1])) ? $variables[1] : true; if( isset($variables[2]) && self::isInteger($variables[2]) ) { self::setHeader($header, $variables[0], $replace, $variables[2]); } else { self::setHeader($header, $variables[0], $replace); } } else { self::setHeader($header, $variables); } } } public static function spaces($count, $htmlentities = true) { $spaces = str_repeat('&nbsp;', (int) $count); return ($htmlentities) ? $spaces : str_replace('&nbsp;', '', $spaces); } public static function tabs($count, $tabsize = 6) { return self::spaces(((int) $tabsize * (int) $count)); } public static function lineBreaks($count, $heightpx = 16) { return str_repeat('<br style="height: ' . $heightpx . 'px;" />', (int) $count); } public static function isArray($variable) { return (is_array($variable)); } public static function isBoolean($variable) { return (is_bool($variable)); } public static function isString($variable) { return (is_string($variable)); } public static function isNull($variable) { return (is_null($variable)); } public static function isCallable($variable) { return (is_callable($variable)); } public static function isObject($variable) { return (is_object($variable)); } public static function isDouble($variable) { return (is_double($variable)); } public static function isFloat($variable) { return (is_float($variable)); } public static function isInteger($variable) { return (is_int($variable)); } public static function isLong($variable) { return (is_long($variable)); } public static function isResource($variable) { return (is_resource($variable)); } public static function getVarType($variable) { $typecases = array( "array" => self::isArray($variable), "boolean" => self::isBoolean($variable), "string" => self::isString($variable), "null" => self::isNull($variable), "callable" => self::isCallable($variable), "object" => self::isObject($variable), "double" => self::isDouble($variable), "integer" => self::isInteger($variable), "float" => self::isFloat($variable), "long" => self::isLong($variable), "resource" => self::isResource($variable) ); foreach($typecases as $type => $bool){ if($bool) return $type; } } public static function nocacheHaders() { if (!headers_sent()) { self::setHeaders(array( "Expires" => "Wed, 11 Jan 1984 05:00:00 GMT", "Last-Modified" => gmdate( 'D, d M Y H:i:s' ) . " GMT", "Cache-Control" => "no-cache, must-revalidate, max-age=0", "Pragma" => "no-cache", )); } } public static function stripSpace(string $string) { return str_replace(' ', '', preg_replace('/\s+/', '', $string)); } public static function sanitize(string $string) { $sanitized = $string; $sanitized = strip_tags($sanitized); $sanitized = htmlspecialchars($sanitized, ENT_QUOTES, 'utf-8'); $sanitized = htmlentities($sanitized, ENT_HTML5, 'utf-8'); return $sanitized; } public static function dumpVar($variable, $doreturn = false, $dopre = true, $styles = true, $tabamt = 1) { $return = ''; $wrapper = ($dopre === null) ? 'none' : ((self::isBoolean($dopre)) ? (($dopre) ? 'pre' : 'div' ) : $dopre ); $class = ($styles) ? 'styled' : 'nostyles'; $settings = array( 'wrappers' => array( 'none' => '%s', 'pre' => '<pre class="vardump ' . $class . '">%s</pre>', 'div' => '<div class="vardump ' . $class . '">%s</div>' ), 'sprintf' => array( 'vartype' => '<span class="vartype">%s</span>', 'specialvartype' => '<span class="specialvartype">%s</span>', 'parentheses' => '<span class="parentheses">(</span><span class="parcont">%s</span><span class="parentheses">)</span>', 'string' => '<span class="misc">"%s"</span>', 'raw' => '<span class="misc">%s</span>', 'arrkey' => '<span class="misc">' . self::tabs($tabamt) . '[%s]</span>', 'arrsep' => '<span class="arrsep">=></span>' ), ); switch(self::getVarType($variable)) { case "boolean": $return .= sprintf($settings['sprintf']['vartype'], 'bool') . sprintf($settings['sprintf']['parentheses'], (string) $variable ? 'true' : 'false'); break; case "integer": $return .= sprintf($settings['sprintf']['vartype'], 'int') . sprintf($settings['sprintf']['parentheses'], (string) $variable); break; case "double": $return .= sprintf($settings['sprintf']['vartype'], 'double') . sprintf($settings['sprintf']['parentheses'], (string) $variable); break; case "float": $return .= sprintf($settings['sprintf']['vartype'], 'float') . sprintf($settings['sprintf']['parentheses'], (string) $variable); break; case "string": $return .= sprintf($settings['sprintf']['vartype'], 'string') . sprintf($settings['sprintf']['parentheses'], (string) strlen($variable)) . " " . sprintf($settings['sprintf']['string'], $variable); break; case "null": $return .= sprintf($settings['sprintf']['specialvartype'], 'NULL'); break; case "array": $brackets = array('{'); foreach($variable as $key => $value) { $brackets[] = sprintf($settings['sprintf']['arrkey'], $key) . " " . $settings['sprintf']['arrsep'] . " " . self::dumpVar($value, true, null, $styles, $tabamt + 1) . ','; } $brackets[] = ($tabamt < 2) ? '}' : self::tabs(($tabamt - 1)) . '}'; $brackets = ($dopre) ? implode("\n", $brackets) : implode('<br />', $brackets); $return .= sprintf($settings['sprintf']['vartype'], 'array') . sprintf($settings['sprintf']['parentheses'], (string) count($variable)) . " " . $brackets; break; case "object": $reflclass = new ReflectionClass($variable); $constants = $reflclass->getConstants(); $variables = $reflclass->getProperties(); $methods = $reflclass->getMethods(); $brackets = array('{'); foreach($constants as $name => $value) { $brackets[] = self::tabs($tabamt) . sprintf($settings['sprintf']['raw'], 'CONST ' . $name) . ' ' . self::dumpVar($value, true, null, $styles); } foreach($variables as $var) { } $return .= sprintf($settings['sprintf']['vartype'], 'object') . sprintf($settings['sprintf']['parentheses'], get_class($variable)); break; default: $return .= sprintf($settings['sprintf']['specialvartype'], 'UNKNOWN TYPE') . ' ' . sprintf($settings['sprintf']['raw'], var_export($variable, true)); break; } if($dopre) $return = str_ireplace('&nbsp;', ' ', $return); $returnwrapper = (array_key_exists($wrapper, $settings['wrappers'])) ? $settings['wrappers'][$wrapper] : $settings['wrappers']['none']; $return = sprintf($returnwrapper, $return); if($doreturn) return $return; echo $return; } public static function dumpVars($variables, $doreturn = false, $dopre = true, $styles = true, $tabamt = 1) { $return = array(); foreach($variables as $var) { $return[] = self::dumpVar($var, true, $dopre, $styles, $tabamt); } $return = implode(self::lineBreaks(1), $return); if($doreturn) return $return; echo $return; } public static function outputData(string $filename, string $content = null, $mimetype = "auto") { $mimetype = (is_file($filename)) ? finfo_file(finfo_open(FILEINFO_MIME, pathinfo($content, PATHINFO_DIRNAME), $content)) : ($mimetype == "auto") ? "application/force-download" : $mimetype; if(!headers_sent()) { $output = is_null($content) ? file_get_contents($file) : $content; self::setHeaders(array( "Pragma" => "public", "Expires" => "0", "Cache-Control" => "must-revalidate, post-check=0, pre-check=0", "Cache-Control" => array("private", FALSE), "Content-Disposition" => "attatchment; filename=" . basename(str_replace('"', '', $filename)) . '";', "Content-Type" => $mimetype, "Content-Transer-Encoding" => "binary", "Content-Length" => strlen($output), )); ob_clean(); flush(); echo $output; exit(); } } public static function forceDownload($file, $content = null) { self::outputData($file, $content, "application/force-download"); } public static function uniqueId($prefix = null, $format = '{35}') // Ex: {8}-{4}-{4}-{4}-{12} will return something like XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX { $uniqueid = $prefix; $alpha = range('a', 'z', 1); $alphacase = range('A', 'Z', 1); $num = range('1', '999', 1); $rand1 = array_rand($alpha, 5); $rand2 = array_rand($alphacase, 5); $rand3 = array_rand($num, 5); $rand = array_merge($rand1, $rand2, $rand3); $datetime = new DateTime('now', new DateTimeZone('America/New_York')); $timestamp = $datetime->format('c'); $uniqueid .= implode('', $rand) . "_" . $timestamp . "_" . uniqid(); $origuniqueid = $uniqueid; foreach(hash_algos() as $algo) { $uniqueid = hash($algo, $uniqueid . "_" . $timestamp . "_" . uniqid()); } $uniqueid = md5($uniqueid); $chararrays = array(); $finaluniqueid = ''; $amount = 10; for($time = $amount; $time > 0; $time--) { $chararrays[$time] = str_split($uniqueid); shuffle($chararrays[$time]); $finaluniqueid .= implode('', array_slice($chararrays[$time], rand(0, (count($chararrays[$time]) - 1)), rand(0, (count($chararrays[$time]) - 1)))); } $finaluniqueid = str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid); $formateduniqueid = $format; $substart = 0; preg_match_all('([0-9]+)', $format, $ints); foreach($ints[0] as $int) { if($newi > strlen($formateduniqueid) ) $newi = strlen($formateduniqueid); $substr = substr($finaluniqueid, $substart, ((int) $int)); $formateduniqueid = preg_replace('/\{' . $int . '\}/', $substr, $formateduniqueid, 1); $substart = $substart + ((int) $int); } return $formateduniqueid; } public static function getRelativePath($from, $to) { $from = is_dir($from) ? rtrim($from, '\/') . '/' : $from; $to = is_dir($to) ? rtrim($to, '\/') . '/' : $to; $from = str_replace('\\', '/', $from); $to = str_replace('\\', '/', $to); $from = explode('/', $from); $to = explode('/', $to); $relPath = $to; foreach($from as $depth => $dir) { if($dir === $to[$depth]) { array_shift($relPath); } else { $remaining = count($from) - $depth; if($remaining > 1) { $padLength = (count($relPath) + $remaining - 1) * -1; $relPath = array_pad($relPath, $padLength, '..'); break; } else { $relPath[0] = './' . $relPath[0]; } } } return implode('/', $relPath); } public static function arrayList(array $array, $withkeys = false, $keysep = ': ') { if($withkeys) { foreach($array as $k => $v) { $array[$k] = $k . $keysep . $v; } } switch(count($array)) { case 1: return implode('', $array); break; case 2: return implode(' and ', $array); break; case 3: $arrv = array_values($array); $array[array_search($arrv[(count($arrv) - 1)], $array)] = 'and ' . $array[array_search($arrv[(count($arrv) - 1)], $array)]; $output = implode(', ', $array); if(strtoupper(Locale::getRegion(Locale::getDefault())) === 'GB') $output = str_replace(', and', ' and ', $output); return $output; } } public static function pluckArrays($key, $value, $arrays) { $return = array(); foreach($arrays as $array) { if($array[$key] === $value) { $return[] = $array; } } return $return; } public static function addQuotes($string, $quote = '"') { return $quote . $string . $quote; } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0120.00618.30
8.3.50.0150.00721.93
8.3.40.0140.00718.98
8.3.30.0130.00319.04
8.3.20.0040.00420.54
8.3.10.0040.00420.59
8.3.00.0050.00319.66
8.2.180.0130.00716.75
8.2.170.0060.00922.96
8.2.160.0070.00720.59
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0040.00422.23
8.2.110.0080.00320.93
8.2.100.0080.00417.63
8.2.90.0040.00419.34
8.2.80.0090.00017.97
8.2.70.0000.00917.49
8.2.60.0080.00017.93
8.2.50.0050.00318.10
8.2.40.0000.00818.34
8.2.30.0060.00319.41
8.2.20.0040.00417.87
8.2.10.0040.00418.14
8.2.00.0000.00817.69
8.1.280.0090.00625.92
8.1.270.0000.00922.35
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0080.00422.29
8.1.230.0040.00819.30
8.1.220.0050.00317.74
8.1.210.0060.00318.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0060.00318.10
8.1.170.0030.00618.57
8.1.160.0070.00022.10
8.1.150.0080.00018.93
8.1.140.0030.00617.61
8.1.130.0080.00018.00
8.1.120.0040.00417.57
8.1.110.0060.00317.56
8.1.100.0050.00317.48
8.1.90.0040.00417.54
8.1.80.0030.00517.50
8.1.70.0000.00817.50
8.1.60.0000.00817.68
8.1.50.0000.00817.52
8.1.40.0000.00917.52
8.1.30.0000.00817.69
8.1.20.0040.00417.75
8.1.10.0050.00317.57
8.1.00.0080.00017.43
8.0.300.0050.00318.77
8.0.290.0000.00816.88
8.0.280.0040.00418.43
8.0.270.0040.00417.35
8.0.260.0070.00017.41
8.0.250.0000.00717.00
8.0.240.0030.00316.98
8.0.230.0000.00817.11
8.0.220.0040.00416.96
8.0.210.0000.00816.95
8.0.200.0000.00717.12
8.0.190.0050.00317.16
8.0.180.0060.00317.05
8.0.170.0030.00617.04
8.0.160.0030.00517.03
8.0.150.0040.00416.94
8.0.140.0080.00016.89
8.0.130.0060.00013.43
8.0.120.0040.00417.02
8.0.110.0060.00316.89
8.0.100.0040.00417.00
8.0.90.0040.00417.05
8.0.80.0030.01216.98
8.0.70.0000.00816.94
8.0.60.0050.00317.02
8.0.50.0040.00417.15
8.0.30.0060.01317.17
8.0.20.0130.01217.40
8.0.10.0080.00017.05
8.0.00.0080.01116.82
7.4.330.0020.00515.00
7.4.320.0070.00016.65
7.4.300.0050.00316.73
7.4.290.0040.00416.74
7.4.280.0070.00316.55
7.4.270.0000.00916.64
7.4.260.0040.00416.71
7.4.250.0000.00816.63
7.4.240.0050.00216.58
7.4.230.0040.00416.45
7.4.220.0060.01316.61
7.4.210.0070.01016.72
7.4.200.0000.00816.80
7.4.160.0090.00916.42
7.4.150.0160.00317.40
7.4.140.0130.00717.86
7.4.130.0070.01016.58
7.4.120.0080.01016.82
7.4.110.0100.00716.48
7.4.100.0080.01516.67
7.4.90.0060.01116.64
7.4.80.0120.00616.63
7.4.70.0060.01016.73
7.4.60.0070.01416.56
7.4.50.0090.00016.72
7.4.40.0090.00816.49
7.4.30.0070.01016.54
7.4.00.0150.00014.86
7.3.330.0030.00313.40
7.3.320.0040.00413.39
7.3.310.0030.00316.25
7.3.300.0030.00416.27
7.3.290.0000.01416.28
7.3.280.0060.00816.36
7.3.270.0110.00817.40
7.3.260.0100.01016.45
7.3.250.0090.01216.43
7.3.240.0030.01416.36
7.3.230.0110.00716.61
7.3.210.0110.00716.45
7.3.200.0100.00919.39
7.3.190.0110.01116.53
7.3.180.0060.01016.53
7.3.170.0060.01416.52
7.3.160.0130.00416.68
7.3.10.0060.01016.73
7.3.00.0080.01016.44
7.2.330.0060.01216.63
7.2.320.0060.01216.38
7.2.310.0110.00716.50
7.2.300.0150.00316.79
7.2.290.0100.01016.65
7.2.130.0060.01216.77
7.2.120.0040.01616.79
7.2.110.0110.00316.83
7.2.100.0070.00416.78
7.2.90.0060.00616.52
7.2.80.0040.01216.54
7.2.70.0140.00016.93
7.2.60.0100.00616.65
7.2.50.0030.00916.67
7.2.40.0100.00316.85
7.2.30.0000.01216.66
7.2.20.0060.00916.66
7.2.10.0070.01116.63
7.2.00.0030.00917.87
7.1.250.0040.01115.36
7.1.100.0060.00617.73
7.1.70.0040.00416.96
7.1.60.0120.01219.32
7.1.50.0130.01316.94
7.1.00.0030.07722.36
7.0.200.0020.00516.49
7.0.140.0070.06721.93
7.0.100.0230.08020.25
7.0.90.0030.09020.07
7.0.80.0100.07320.10
7.0.70.0370.07720.34
7.0.60.0330.08720.27
7.0.50.0330.07320.50
7.0.40.0070.08320.13
7.0.30.0100.06020.18
7.0.20.0130.06020.11
7.0.10.0100.06720.15
7.0.00.0070.09020.01
5.6.280.0070.07321.22
5.6.250.0000.08720.85
5.6.240.0230.06020.63
5.6.230.0100.08720.63
5.6.220.0100.07720.74
5.6.210.0070.08720.59
5.6.200.0230.06321.30
5.6.190.0030.04321.08
5.6.180.0030.05721.15
5.6.170.0070.08321.08
5.6.160.0070.05321.19
5.6.150.0130.07321.29
5.6.140.0100.07721.25
5.6.130.0100.08021.21
5.6.120.0130.05321.12
5.6.110.0070.05321.09
5.6.100.0100.04721.05
5.6.90.0100.04321.13
5.6.80.0030.04020.58
5.6.70.0100.03320.52
5.6.60.0030.04020.60
5.6.50.0100.03320.59
5.6.40.0000.05320.52
5.6.30.0030.06720.60
5.6.20.0030.03720.55
5.6.10.0170.07320.55
5.6.00.0130.04320.48
5.5.380.0070.08720.58
5.5.370.0070.05020.49
5.5.360.0070.08320.46
5.5.350.0070.05020.50
5.5.340.0070.05020.76
5.5.330.0100.07721.02
5.5.320.0300.06721.04
5.5.310.0070.08021.01
5.5.300.0070.05021.00
5.5.290.0130.04020.88
5.5.280.0070.05320.88
5.5.270.0030.05320.93
5.5.260.0000.04721.03
5.5.250.0130.03720.84
5.5.240.0030.06720.31
5.5.230.0000.04320.34
5.5.220.0030.04020.25
5.5.210.0070.03720.43
5.5.200.0070.04320.37
5.5.190.0000.04320.28
5.5.180.0030.06320.28
5.5.160.0200.06720.30
5.5.150.0070.05720.30
5.5.140.0170.05020.38
5.5.130.0030.06020.28
5.5.120.0030.03720.38
5.5.110.0100.03720.39
5.5.100.0070.03720.20
5.5.90.0100.03720.10
5.5.80.0030.05020.19
5.5.70.0100.03720.21
5.5.60.0030.03720.21
5.5.50.0070.03720.13
5.5.40.0100.03020.22
5.5.30.0070.04020.12
5.5.20.0130.02720.25
5.5.10.0000.04320.09
5.5.00.0100.03020.17
5.4.450.0130.07019.23
5.4.440.0070.07719.56
5.4.430.0070.04019.41
5.4.420.0100.03719.24
5.4.410.0130.03719.10
5.4.400.0070.03719.11
5.4.390.0000.04719.11
5.4.380.0070.04018.93
5.4.370.0070.03719.23
5.4.360.0000.04319.09
5.4.350.0070.05719.09
5.4.340.0070.07319.09
5.4.320.0070.03319.05
5.4.310.0070.04319.01
5.4.300.0000.04019.13
5.4.290.0000.08319.23
5.4.280.0070.05319.14
5.4.270.0000.04319.09
5.4.260.0070.04719.00
5.4.250.0000.04019.23
5.4.240.0000.04019.27
5.4.230.0000.04018.91
5.4.220.0000.04018.90
5.4.210.0000.03719.14
5.4.200.0030.06719.20
5.4.190.0030.03719.30
5.4.180.0030.04019.08
5.4.170.0030.04019.09
5.4.160.0030.04319.21
5.4.150.0100.03719.21
5.4.140.0000.04016.45
5.4.130.0000.06716.50
5.4.120.0130.03316.48
5.4.110.0170.02316.59
5.4.100.0070.05016.42
5.4.90.0030.03016.42
5.4.80.0070.04016.37
5.4.70.0070.03316.37
5.4.60.0070.03016.52
5.4.50.0000.04016.40
5.4.40.0000.03316.50
5.4.30.0000.04016.54
5.4.20.0000.04016.53
5.4.10.0000.04016.43
5.4.00.0000.04015.88

preferences:
43.51 ms | 401 KiB | 5 Q