3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class ErrorLog { var $errorArr = array(); 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"] . "."; } } $out = "\"" . $err . "\" " . $info; if (!$suppress) { trigger_error($out, $level); } } function throwDeprecated ($suppress = false) { // Call this method from INSIDE a deprecated function, ErrorLog::throwError("Deprecated!", E_USER_NOTICE, $suppress, 2); } 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/ODUAf on line 76 Deprecated: Non-static method ErrorLog::throwError() should not be called statically in /in/ODUAf on line 62 Deprecated: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/ODUAf on line 21 Notice: "Deprecated!" in /in/ODUAf:76. Thrown by a() which was called in /in/ODUAf:79. in /in/ODUAf on line 55
Output for 5.2.3 - 5.4.45, hhvm-3.10.0 - 3.12.0
Notice: "Deprecated!" in /in/ODUAf:76. Thrown by a() which was called in /in/ODUAf:79. in /in/ODUAf on line 55
Output for 5.5.0 - 5.6.28
Strict Standards: Non-static method ErrorLog::throwDeprecated() should not be called statically in /in/ODUAf on line 76 Strict Standards: Non-static method ErrorLog::throwError() should not be called statically in /in/ODUAf on line 62 Strict Standards: Non-static method ErrorLog::getBacktrace() should not be called statically in /in/ODUAf on line 21 Notice: "Deprecated!" in /in/ODUAf:76. Thrown by a() which was called in /in/ODUAf:79. in /in/ODUAf on line 55
Output for 4.3.0 - 5.2.2
<br /> <b>Notice</b>: "Deprecated!" in /in/ODUAf:76. Thrown by a() which was called in /in/ODUAf:79. in <b>/in/ODUAf</b> on line <b>55</b><br />