3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class ErrorLog { static $errorArr = array(); public 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 = self::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; self::$errorArr[] = $err; if (!$suppress) { trigger_error($out, $level); } } public function throwDeprecated ($suppress = false) { // Call this method from INSIDE a deprecated function, self::throwError("Deprecated!", E_USER_NOTICE, $suppress, 2); } private 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 7.0.0 - 7.1.0
Deprecated: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/LtqHX on line 82 Deprecated: Non-static method ErrorLog::throwError() should not be called statically in /in/LtqHX on line 68 Deprecated: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/LtqHX on line 22 Notice: Undefined index: QUERY_STRING in /in/LtqHX on line 53 Notice: Undefined index: HOST_NAME in /in/LtqHX on line 54 Notice: "Deprecated!" in /in/LtqHX:82. Thrown by a() which was called in /in/LtqHX:85. (Called URL: /in/LtqHX) in /in/LtqHX on line 61
Output for 5.3.0 - 5.6.28
Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/LtqHX on line 82 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/LtqHX on line 68 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/LtqHX on line 22 Notice: Undefined index: QUERY_STRING in /in/LtqHX on line 53 Notice: Undefined index: HOST_NAME in /in/LtqHX on line 54 Notice: "Deprecated!" in /in/LtqHX:82. Thrown by a() which was called in /in/LtqHX:85. (Called URL: /in/LtqHX) in /in/LtqHX on line 61
Output for 5.2.3 - 5.2.17
Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/LtqHX on line 82 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/LtqHX on line 68 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/LtqHX on line 22 Notice: Undefined index: QUERY_STRING in /in/LtqHX on line 53 Notice: Undefined index: HOST_NAME in /in/LtqHX on line 54 Notice: "Deprecated!" in /in/LtqHX:82. Thrown by a() which was called in /in/LtqHX:85. (Called URL: /in/LtqHX) in /in/LtqHX on line 61
Output for 5.0.0 - 5.2.2
Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/LtqHX on line 82 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/LtqHX on line 68 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/LtqHX on line 22 Notice: Undefined index: QUERY_STRING in /in/LtqHX on line 53 Notice: Undefined index: HOST_NAME in /in/LtqHX on line 54 Notice: "Deprecated!" in /in/LtqHX:82. Thrown by a() which was called in /in/LtqHX:85. (Called URL: ) in /in/LtqHX on line 61
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/LtqHX on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/LtqHX on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/LtqHX on line 4
Process exited with code 255.