Bug #75323 [Opn->Fbk]: auto_prepend_file doesn't work with other functions
Edit report at https://bugs.php.net/bug.php?id=75323&edit=1
ID: 75323
Updated by: ab@php.net
Reported by: toolscom at hotmail dot com
Summary: auto_prepend_file doesn't work with other functions
-Status: Open
+Status: Feedback
Type: Bug
Package: Unknown/Other Function
Operating System: Windows 2012
PHP Version: 7.1.10
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2017-10-05 21:19:16] 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");
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75323&edit=1
Thread (3 messages)