Bug #75323 [Fbk->NoF]: auto_prepend_file doesn't work with other functions

From: Date: Sun, 05 Nov 2017 04:22:57 +0000
Subject: Bug #75323 [Fbk->NoF]: auto_prepend_file doesn't work with other functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212465@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75323&edit=1 ID: 75323 Updated by: php-bugs@lists.php.net Reported by: toolscom at hotmail dot com Summary: auto_prepend_file doesn't work with other functions -Status: Feedback +Status: No Feedback Type: Bug Package: Unknown/Other Function Operating System: Windows 2012 PHP Version: 7.1.10 Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2017-10-09 08:49:10] ab@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#212465) next »