3v4l.org

run code in 300+ PHP versions simultaneously
<?php if(!defined('E_DEPRECATED')){ define('E_DEPRECATED', 0); } if(!defined('E_USER_DEPRECATED')){ define('E_USER_DEPRECATED', 0); } const EHS_ERRORS = array( E_ERROR => array('ERROR', 'Error'), E_WARNING => array('WARNING', 'Warning'), E_PARSE => array('PARSE', 'Parsing Error'), E_NOTICE => array('NOTICE', 'Notice'), E_CORE_ERROR => array('CORE_ERROR', 'Core Error'), E_CORE_WARNING => array('CORE_WARNING', 'Core Warning'), E_COMPILE_ERROR => array('COMPILE_ERROR', 'Compile Error'), E_COMPILE_WARNING => array('COMPILE_WARNING', 'Compile Warning'), E_USER_ERROR => array('USER_ERROR', 'Triggered Error'), E_USER_WARNING => array('USER_WARNING', 'Triggered Warning'), E_USER_NOTICE => array('USER_NOTICE', 'Triggered Notice'), E_STRICT => array('STRICT', 'Strict Standarts'), E_RECOVERABLE_ERROR => array('RECOVERABLE_ERROR', 'Catchable Fatal Error'), E_DEPRECATED => array('DEPRECATED', 'Deprecated'), E_USER_DEPRECATED => array('USER_DEPRECATED', 'Triggered Deprecated') ); define('EHS_CHECK_TOKENS_RGX', "/\(T_(".implode('|', array_keys(EHS_TOKENS)).")\)/"); define('EHS_NL', "<br>"); define('EHS_OPEN', "<div style='padding:1px;margin:1px 0;white-space:pre-wrap;border:1px solid black;word-wrap:break-word;'>"); define('EHS_SOURCE_OPEN', "<div style='padding:1px;margin:1px 0 0;white-space:pre-wrap;border:1px solid black;word-wrap:break-word;tab-size:2;font-family:monospace;'>"); define('EHS_CLOSE', "</div>"); define('EHS_OFF', 1); define('EHS_GET_BACKTRACE', 2); define('EHS_GET_SOURCE', 4); define('EHS_GET_TOKEN_EXAMPLE',8); define('EHS_GET_TOKEN_INFO', 16); define('EHS_GET_MEMORY_USAGE', 32); define('EHS_DEBUG', 64); define('EHS_MUST_IGNORE_REPORTING', 128); define('EHS_ALL', (4096 - 1) ^ EHS_OFF); define('EHS_UTF', (extension_loaded('mbstring') ? (ini_get('mbstring.internal_encoding') == 'UTF-8') : false)); class EHS { public static $previousAssertOptions = array(); public static $instance = null; public $maxchars = 30; public $linkFormat = ''; public $mask = 0; public function __construct($mask = EHS_OFF){ if(self::$instance != null){ throw new Exception('EHS Object already exists, check EHS::$instance'); } $this->mask = $mask; self::$instance = &$this; } public function reporting($E = null){ if($E === null){ return error_reporting(); }else{ error_reporting($E); } return $this; } public function displayAllErrors(){ $this->reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); return $this; } public function setup($error = false, $fatal = false, $exception = false, $assert = false){ if($error){ set_error_handler(array($this, 'ErrorHandler')); } if($fatal){ register_shutdown_function(array($this, 'FatalErrorHandler')); ob_start(); } if($exception){ set_exception_handler(array($this, 'ExceptionHandler')); } if($assert){ self::$previousAssertOptions[ASSERT_ACTIVE] = assert_options(ASSERT_ACTIVE); self::$previousAssertOptions[ASSERT_WARNING] = assert_options(ASSERT_ACTIVE); self::$previousAssertOptions[ASSERT_BAIL] = assert_options(ASSERT_BAIL); self::$previousAssertOptions[ASSERT_QUIET_EVAL] = assert_options(ASSERT_QUIET_EVAL); self::$previousAssertOptions[ASSERT_CALLBACK] = assert_options(ASSERT_CALLBACK); assert_options(ASSERT_ACTIVE, 1); assert_options(ASSERT_WARNING, 0); assert_options(ASSERT_BAIL, 0); assert_options(ASSERT_QUIET_EVAL, 0); assert_options(ASSERT_CALLBACK, array($this, 'AssertionHandler')); } return $this; } public function setupEnvironment(){ ini_set('html_errors', 'On'); ini_set('docref_root', ''); ini_set('docref_ext', ''); ini_set('log_errors', 'On'); ini_set('log_errors_max_len', 0); ini_set('ignore_repeated_errors', 'Off'); ini_set('ignore_repeated_source', 'Off'); ini_set('report_memleaks', 'Off'); ini_set('track_errors', 'On'); ini_set('xmlrpc_errors', 'Off'); ini_set('xmlrpc_error_number', 'Off'); ini_set('error_prepend_string', ''); ini_set('error_append_string', ''); return $this; } public function restore($error = false, $exception = false, $assert = false){ if($error){ restore_error_handler(); } if($exception){ restore_exception_handler(); } if($assert){ assert_options(ASSERT_ACTIVE, self::$previousAssertOptions[ASSERT_ACTIVE]); assert_options(ASSERT_WARNING, self::$previousAssertOptions[ASSERT_WARNING]); assert_options(ASSERT_BAIL, self::$previousAssertOptions[ASSERT_BAIL]); assert_options(ASSERT_QUIET_EVAL, self::$previousAssertOptions[ASSERT_QUIET_EVAL]); assert_options(ASSERT_CALLBACK, self::$previousAssertOptions[ASSERT_CALLBACK]); } return $this; } public function ErrorHandler($code, $message, $file, $line, $context = INF){ if(($this->mask & EHS_OFF) || ($ignored = $this->ignoreReporting($code)) == 'X'){ return false; }else{ $debug = ($this->mask & EHS_DEBUG) || !($code & (E_NOTICE | E_USER_NOTICE | E_DEPRECATED | E_USER_DEPRECATED | E_STRICT)); $types = EHS_ERRORS[$code]; $text = EHS_OPEN; $text .= "<b>[".date('d-M-Y H:i:s')."] $ignored [E_$types[0]]".(($this->mask & EHS_GET_MEMORY_USAGE) && $debug ? ' [Memory Usage: '.memory_get_usage().' Bytes]' : '')."</b>".EHS_NL; $text .= "<b>$types[1]:</b> {$message}".EHS_NL; $text .= " in <b>[{$this->formatLink($file, $line)}]</b>".EHS_NL; if($debug){ $text .= $this->getErrorSourceCode($file, $line); if($this->mask & EHS_GET_BACKTRACE){ $text .= $this->formatBacktrace($this->backtrace(), $context === INF ? 3 : 2); } } echo $text.EHS_CLOSE; return true; } } public function FatalErrorHandler(){ $error = error_get_last(); if($error && $error['type'] & (E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR)){ while(ob_get_level()){ ob_end_clean(); } $this->ErrorHandler($error['type'], $error['message'], $error['file'], $error['line']); exit; }else{ ob_end_flush(); } } public function ExceptionHandler($e){ $hasChain = !!$e->getPrevious(); $text = ($hasChain ? EHS_OPEN : ''); $date = date('d-M-Y H:i:s'); do{ if($e instanceof ErrorException){ $text .= $this->ErrorException($e, $date); }else{ $text .= $this->Exception($e, $date); } }while($e = $e->getPrevious()); $text .= ($hasChain ? EHS_CLOSE : ''); echo $text; } protected function ErrorException($e, $date){ $code = $e->getCode(); $file = $e->getFile(); $line = $e->getLine(); $severity = $e->getSeverity(); $types = EHS_ERRORS[$severity] ?: array('UNKNOWN', 'Unknown'); $text = EHS_OPEN; $text .= "<b>[$date] [E_$types[0]]".($code ? " [Code: $code]" : '')."</b>".EHS_NL; $text .= "<b>$types[1] Exception:</b> {$e->getMessage()}".EHS_NL; $text .= " thrown in <b>[{$this->formatLink($file, $line)}]</b>".EHS_NL; $text .= $this->getErrorSourceCode($file, $line); $text .= $this->formatBacktrace($e->getTrace()); $text .= EHS_CLOSE; return $text; } protected function Exception($e, $date){ $code = $e->getCode(); $file = $e->getFile(); $line = $e->getLine(); $text = EHS_OPEN; $text .= "<b>[$date]".($code ? " [Code: $code]" : '')."</b>".EHS_NL; $text .= "<b>".get_class($e).":</b> {$e->getMessage()}".EHS_NL; $text .= " thrown in <b>[{$this->formatLink($file, $line)}]</b>".EHS_NL; $text .= $this->getErrorSourceCode($file, $line); $text .= $this->formatBacktrace($e->getTrace()); $text .= EHS_CLOSE; return $text; } public function AssertionHandler($file, $line, $code, $message = ''){ $text = EHS_OPEN; $text .= "<b>[".date('d-M-Y H:i:s')."]</b>".EHS_NL; $text .= "<b>Assertion Failed:</b> $message".($code ? " ($code)" : '').EHS_NL; $text .= " in <b>[{$this->formatLink($file, $line)}]</b>".EHS_NL; echo $text.EHS_CLOSE; return true; } protected function formatBacktrace($trace, $init = 0){ $length = count($trace); if($length > $init){ $text = EHS_SOURCE_OPEN.'Trace:'; for($i = $init; $i < $length; $i++){ $point = $trace[$i]; $text .= EHS_NL.' \–––> '; $args = isset($point['args']) ? $this->formatArgs($point['args']) : '()'; $text .= isset($point['class']) ? $point['class'] : ''; $text .= isset($point['type']) ? $point['type'] : ''; $text .= isset($point['function']) ? $point['function'].$args : '???'; $text .= EHS_NL.' at ['.(isset($point['file']) ? $this->formatLink($point['file'], (isset($point['line']) ? $point['line'] : 0)) : 'unknown').']'; } unset($trace); return $text.EHS_CLOSE; }else{ return ''; } } protected function getErrorSourceCode($file, $line){ if(($this->mask & EHS_GET_SOURCE) && $file && $line && ($lines = file($file)) !== false){ $max_length = $this->stringLength((string) ($line + 1)); $compile = function($num, $line) use ($max_length){ $out = $num.str_repeat(' ', $max_length - $this->stringLength((string) $num))." | ".htmlspecialchars($line); return $out; }; $text = EHS_SOURCE_OPEN; $text .= ($lines[$line - 2] ? $compile($line - 1, $lines[$line - 2]) : ''); $text .= "<font style='display:block;background:rgba(255, 165, 165, 0.3);'>".$compile($line, $lines[$line - 1])."</font>"; $text .= ($lines[$line] ? $compile($line + 1, $lines[$line]) : ''); return $text.EHS_CLOSE; }else{ return ''; } } protected function ignoreReporting($code){ if(!(error_reporting() & $code)){ if($this->mask & EHS_MUST_IGNORE_REPORTING){ return '@'; }else{ return 'X'; } } return ''; } protected function formatLink($file, $line){ if(!$file || !$this->linkFormat){ return "{$this->shortFile($file)}:$line"; } return "<a href='".str_replace(array('%f', '%l'), array(urlencode($file), $line), $this->linkFormat)."' style='color:black;'>{$this->shortFile($file)}:$line</a>"; } protected function shortFile($file){ return str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', $file)); } protected function backtrace(){ if(defined('DEBUG_BACKTRACE_PROVIDE_OBJECT')){ return debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT); }else{ return debug_backtrace(true); } } protected function formatString($str){ if($this->stringLength($str) > $this->maxchars){ if(EHS_UTF){ $str = trim(mb_substr($str, 0, $this->maxchars / 2)).'…'.trim(mb_substr($str, -$this->maxchars / 2)); }else{ $str = substr($str, 0, $this->maxchars / 2).'...'.substr($str, -$this->maxchars / 2); } } return $str; } protected function stringLength($str){ if(EHS_UTF){ $strlen = mb_strlen($str); }else{ $strlen = strlen($str); } return $strlen; } protected function formatArg($arg){ switch(gettype($arg)){ case 'boolean': return $arg ? 'true' : 'false'; case 'NULL': return 'null'; case 'integer': case 'double': case 'float': $arg = (string) $arg; if(EHS_UTF){ $arg = str_replace('INF', '∞', $arg); }else{ $arg = str_replace('INF', 'Infinity', $arg); } $arg = str_replace('NAN', 'NaN', $arg); return $arg; case 'string': if(is_callable($arg, false, $name)){ return "fs:$name"; }else if(class_exists($arg, false)){ return "c:$arg"; }else if(interface_exists($arg, false)){ return "i:$arg"; }else if(function_exists('trait_exists') && trait_exists($arg, false)){ return "t:$arg"; }else{ $strlen = $this->stringLength($arg); $arg = $this->formatString($arg); if($strlen <= $this->maxchars){ $arg = "\"$arg\""; }else{ $arg = "\"$arg\"($strlen)"; } return str_replace("\n", '\n', str_replace("\t", '\t', $arg)); } case 'array': if(is_callable($arg, false, $name)){ return "fa:$name"; }else{ return 'array('.count($arg).')'; } case 'object': $object = get_class($arg).'():'.spl_object_hash($arg); if(is_callable($arg, false)){ $object = "fo:".$object; } return $object; case 'resource': return 'r:'.get_resource_type($arg); default: return 'unknown'; } } protected function formatArgs($args){ foreach($args as &$value){ $value = $this->formatArg($value); } return '('.implode(', ', $args).')'; } } ?>

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.00616.88
8.3.50.0030.01216.75
8.3.40.0070.01019.04
8.3.30.0060.00919.05
8.3.20.0050.00322.12
8.3.10.0050.00322.02
8.3.00.0080.00019.21
8.2.180.0070.00718.41
8.2.170.0120.00322.96
8.2.160.0110.00420.36
8.2.150.0090.00024.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0070.00419.51
8.2.110.0070.00322.30
8.2.100.0040.00818.16
8.2.90.0000.00818.28
8.2.80.0040.00419.40
8.2.70.0000.00917.75
8.2.60.0030.00518.00
8.2.50.0000.00817.88
8.2.40.0000.00820.61
8.2.30.0000.00919.54
8.2.20.0030.00518.24
8.2.10.0030.00618.16
8.2.00.0000.00918.34
8.1.280.0110.01125.92
8.1.270.0030.00620.41
8.1.260.0060.00626.35
8.1.250.0050.00328.09
8.1.240.0090.00022.41
8.1.230.0110.00021.25
8.1.220.0040.00417.91
8.1.210.0040.00419.04
8.1.200.0060.00317.88
8.1.190.0050.00517.60
8.1.180.0080.00018.10
8.1.170.0030.00619.00
8.1.160.0050.00319.05
8.1.150.0000.00819.19
8.1.140.0040.00417.87
8.1.130.0000.00820.54
8.1.120.0000.00717.59
8.1.110.0000.00817.51
8.1.100.0000.00817.61
8.1.90.0040.00417.63
8.1.80.0040.00417.66
8.1.70.0040.00417.52
8.1.60.0000.00917.62
8.1.50.0030.00517.73
8.1.40.0030.00517.59
8.1.30.0000.00817.71
8.1.20.0060.00617.71
8.1.10.0030.00617.67
8.1.00.0030.00617.64
8.0.300.0050.00320.41
8.0.290.0000.00817.00
8.0.280.0040.00418.63
8.0.270.0030.00617.54
8.0.260.0070.00317.02
8.0.250.0000.00717.19
8.0.240.0060.00317.23
8.0.230.0050.00317.23
8.0.220.0040.00417.08
8.0.210.0030.00517.11
8.0.200.0040.00417.27
8.0.190.0070.00317.27
8.0.180.0000.00817.21
8.0.170.0000.00917.23
8.0.160.0060.00317.16
8.0.150.0000.00817.06
8.0.140.0040.00417.20
8.0.130.0030.00313.61
8.0.120.0030.00617.20
8.0.110.0080.00017.23
8.0.100.0080.00017.13
8.0.90.0040.00417.30
8.0.80.0130.01017.13
8.0.70.0040.00417.14
8.0.60.0050.00317.00
8.0.50.0030.00517.15
8.0.30.0100.01017.21
8.0.20.0090.01217.46
8.0.10.0030.00517.36
8.0.00.0110.00717.02
7.4.330.0030.00315.55
7.4.320.0000.00716.60
7.4.300.0030.00316.66
7.4.290.0040.00416.56
7.4.280.0030.00616.80
7.4.270.0000.00716.57
7.4.260.0070.00016.75
7.4.250.0030.00516.62
7.4.240.0000.00716.75
7.4.230.0050.00316.59
7.4.220.0040.00416.83
7.4.210.0140.00516.67
7.4.200.0040.00416.57
7.4.160.0050.01416.73
7.4.140.0090.01217.86
7.4.130.0070.01116.56
7.4.120.0130.00816.75
7.4.110.0130.01316.59
7.4.100.0040.01316.67
7.4.90.0090.00916.68
7.4.80.0030.01619.39
7.4.70.0160.01016.82
7.4.60.0130.00416.76
7.4.50.0080.01216.80
7.4.40.0070.01116.76
7.4.00.0050.01315.11
7.3.330.0030.00313.47
7.3.320.0000.00613.36
7.3.310.0040.00416.41
7.3.300.0040.00416.52
7.3.290.0000.00716.33
7.3.280.0100.00816.54
7.3.260.0100.00816.69
7.3.240.0110.00816.56
7.3.230.0040.01416.56
7.3.210.0110.00716.68
7.3.200.0150.00316.77
7.3.190.0130.01016.64
7.3.180.0070.01116.43
7.3.170.0130.00916.82
7.3.160.0050.01216.68
7.3.120.0000.01715.06
7.3.110.0100.01015.22
7.3.100.0030.01614.88
7.3.90.0070.00715.20
7.3.80.0060.00614.83
7.3.70.0030.01015.07
7.3.60.0040.01215.05
7.3.50.0130.00615.10
7.3.40.0090.00615.05
7.3.30.0120.00614.91
7.3.20.0070.00716.70
7.3.10.0080.00516.52
7.3.00.0060.00616.60
7.2.330.0060.01316.89
7.2.320.0090.00916.66
7.2.310.0070.01116.54
7.2.300.0060.01216.57
7.2.290.0110.01616.73
7.2.250.0140.00714.88
7.2.240.0070.01115.22
7.2.230.0090.00315.37
7.2.220.0030.01015.19
7.2.210.0050.00515.16
7.2.200.0090.00615.34
7.2.190.0080.00814.93
7.2.180.0040.01215.23
7.2.170.0030.01315.43
7.2.130.0000.01516.89
7.2.120.0040.01116.93
7.2.110.0030.00716.92
7.2.100.0060.00516.85
7.2.90.0090.00316.87
7.2.80.0070.00816.82
7.2.70.0020.01117.01
7.2.60.0060.00816.95
7.2.50.0050.00917.02
7.2.40.0090.00917.24
7.2.30.0140.00717.45
7.2.20.0090.00917.26
7.2.10.0110.01017.35
7.2.00.0090.01117.22
7.1.330.0070.00715.75
7.1.320.0040.00715.72
7.1.310.0080.00615.80
7.1.300.0090.00915.91
7.1.290.0030.01315.68
7.1.280.0110.00715.43
7.1.270.0030.00615.61
7.1.260.0000.01215.67
7.1.250.0060.00615.78
7.1.240.0040.01215.71
7.1.230.0140.00015.66
7.1.220.0030.00915.59
7.1.210.0060.00915.54
7.1.200.0090.00315.68
7.1.190.0030.01015.69
7.1.180.0030.00715.81
7.1.170.0070.00715.61
7.1.160.0090.01316.32
7.1.150.0110.01416.36
7.1.140.0120.01216.28
7.1.130.0140.01216.42
7.1.120.0120.00916.22
7.1.110.0140.00916.10
7.1.100.0110.01016.08
7.1.90.0120.01216.05
7.1.80.0160.00915.97
7.1.70.0100.01515.52
7.1.60.0260.01724.45
7.1.50.0290.01324.12
7.1.40.0270.01124.20
7.1.30.0280.01524.22
7.1.20.0240.01124.28
7.1.10.0150.01415.21
7.1.00.0150.00815.22
7.0.330.0070.00715.52
5.6.380.0090.00614.30

preferences:
51.97 ms | 400 KiB | 5 Q