3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ErrorLog { /*static*/ var $errorArr = array(); /*public static*/ function throwError ($err, $level = E_USER_WARNING, $suppress = false, $shiftBack = 1) { // Shiftback means: look back into the backtrace calls, shifting that amount of calls, and then report the error. // There is no checking whether this many levels actually exist in the call stack, make sure yourself // Error log doesn't show newlines. str_replace( array( "\n" ), array( " " ), $err ); $trace = ErrorLog::getBacktrace(); $info = ""; if (!empty($trace)) { while ($shiftBack > 0) { array_shift($trace); --$shiftBack; } // Error file/line information: $info .= "in " . $trace[0]["file"] . ":" . $trace[0]["line"] . "."; // Caller information: if (count($trace) > 1) { array_shift($trace); $caller = $trace[0]; $info .= " Thrown by "; if (isset($caller["function"])) { if (isset($caller["class"])) { $info .= $caller["class"] . "::"; } $info .= $caller["function"] . "() "; } else { $info .= "global scope "; } $info .= "which was called in " . $caller["file"] . ":" . $caller["line"] . "."; } } $queryStr = $_SERVER["QUERY_STRING"]; $info .= " (Called URL: " . $_SERVER["HOST_NAME"] . $_SERVER["PHP_SELF"] . (!empty($queryStr) ? ("?" . $queryStr) : "") . ")"; $out = "\"" . $err . "\" " . $info; ErrorLog::$errorArr[] = $err; if (!$suppress) { trigger_error($out, $level); } } /*public static*/ function throwDeprecated ($suppress = false) { // Call this method from INSIDE a deprecated function, ErrorLog::throwError("Deprecated!", E_USER_NOTICE, $suppress, 2); } /*public static*/ function hasErrors () { return (!empty(ErrorLog::$errorArr)); } /*private static*/ function getBacktrace () { if (version_compare(PHP_VERSION, "5.2.5", "<")) { return debug_backtrace(); } else { return debug_backtrace(false); // A bit more efficient } } } function a () { ErrorLog::throwDeprecated(); } a();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Non-static method ErrorLog::throwDeprecated() cannot be called statically in /in/mVhXG:94 Stack trace: #0 /in/mVhXG(97): a() #1 {main} thrown in /in/mVhXG on line 94
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/mVhXG on line 94 Deprecated: Non-static method ErrorLog::throwError() should not be called statically in /in/mVhXG on line 72 Deprecated: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/mVhXG on line 25 Notice: Undefined index: QUERY_STRING in /in/mVhXG on line 56 Notice: Undefined index: HOST_NAME in /in/mVhXG on line 57 Fatal error: Uncaught Error: Access to undeclared static property: ErrorLog::$errorArr in /in/mVhXG:61 Stack trace: #0 /in/mVhXG(72): ErrorLog::throwError('Deprecated!', 1024, false, 0) #1 /in/mVhXG(94): ErrorLog::throwDeprecated() #2 /in/mVhXG(97): a() #3 {main} thrown in /in/mVhXG on line 61
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught Error: Access to undeclared static property: ErrorLog::$errorArr in /in/mVhXG:61 Stack trace: #0 /in/mVhXG(72): ErrorLog::throwError('Deprecated!', 1024, false, 0) #1 /in/mVhXG(94): ErrorLog::throwDeprecated() #2 /in/mVhXG(97): a() #3 {main} thrown in /in/mVhXG on line 61
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/mVhXG on line 94 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/mVhXG on line 72 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/mVhXG on line 25 Notice: Undefined index: QUERY_STRING in /in/mVhXG on line 56 Notice: Undefined index: HOST_NAME in /in/mVhXG on line 57 Fatal error: Access to undeclared static property: ErrorLog::$errorArr in /in/mVhXG on line 61
Process exited with code 255.
Output for 5.2.6 - 5.2.17
Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/mVhXG on line 94 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/mVhXG on line 72 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/mVhXG on line 25 Notice: Undefined index: QUERY_STRING in /in/mVhXG on line 56 Notice: Undefined index: HOST_NAME in /in/mVhXG on line 57 Fatal error: Access to undeclared static property: ErrorLog::$errorArr in /in/mVhXG on line 61
Process exited with code 255.
Output for 5.1.3 - 5.1.6, 5.2.0 - 5.2.5
Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/mVhXG on line 94 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/mVhXG on line 72 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/mVhXG on line 25 Notice: Undefined index: QUERY_STRING in /in/mVhXG on line 56 Notice: Undefined index: HOST_NAME in /in/mVhXG on line 57 Fatal error: Access to undeclared static property: ErrorLog::$errorArr in /in/mVhXG on line 61
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/mVhXG on line 6 Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/mVhXG on line 94 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/mVhXG on line 72 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/mVhXG on line 25 Notice: Undefined index: QUERY_STRING in /in/mVhXG on line 56 Notice: Undefined index: HOST_NAME in /in/mVhXG on line 57 Fatal error: Access to undeclared static property: ErrorLog::$errorArr in /in/mVhXG on line 61
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot use [] for reading in /in/mVhXG on line 61
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot use [] for reading in /in/mVhXG on line 61

preferences:
312.85 ms | 401 KiB | 397 Q