|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-10-05 21:19 UTC] toolscom at hotmail dot com
Description:
------------
If you use a set_error_handler() or register_shutdown_function() inside and (auto_prepend_file = "file.php") unusual behaviors such as register_shutdown_function() will not work on fatal error as well as the set_error_handler() will pass errors/warnings incorrectly to the function receiving the error. If you don't use the auto_prepend_file and place the code in say your index.php file and create an error the code will work fine
[.user.ini]
auto_prepend_file = "C:\IIS\Sites\site\test\log.php"
Test script:
---------------
function myErrorHandlerr($errno, $errstr, $errfile, $errline, $error_context) {
$servername = "localhost";
$username = "root";
$password = "Tashia123";
$dbname = "log";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind
$stmt = $conn->prepare("INSERT INTO error_logs (error) VALUES (?)");
$errorssssss = $errstr.$errfile. $errline.$errno . json_encode($error_context);
//
$stmt->bind_param("s", $errorssssss);
// echo $errline;
$stmt->execute();
$stmt->close();
$conn->close();
}
function shutdownHandler() //will be called when php script ends.
{
$lasterror = error_get_last();
switch ($lasterror['type'])
{
case E_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
case E_RECOVERABLE_ERROR:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_PARSE:
$error = "[SHUTDOWN] lvl:" . $lasterror['type'] . " | msg:" . $lasterror['message'] . " | file:" . $lasterror['file'] . " | ln:" . $lasterror['line'];
myErrorHandlerr($error, "fatal",'','','');
}
}
// Set user-defined error handler function
set_error_handler("myErrorHandlerr", E_ALL | E_STRICT);
register_shutdown_function("shutdownHandler");
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
Thanks for the report. Could you please clarify, what exactly is incorrect? Fe i use an index.php containing "$x = 1/0;" and set your code with a small modification to write into a file as auto_prepend_file in .user.ini. It creates a log file where i see 'Division by zero' 'E:\local_programs\nginx\html\bug75323\index.php' '5' '2' {"_GET":[],"_POST":[],"_COOKIE":[],"_FILES":[]} which all seems correct. Thanks.