php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75323 auto_prepend_file doesn't work with other functions
Submitted: 2017-10-05 21:19 UTC Modified: 2017-11-05 04:22 UTC
From: toolscom at hotmail dot com Assigned:
Status: No Feedback Package: Unknown/Other Function
PHP Version: 7.1.10 OS: Windows 2012
Private report: No CVE-ID: None
 [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");


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-09 08:49 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2017-10-09 08:49 UTC] 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-11-05 04:22 UTC] php-bugs at lists dot php dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 09 04:01:30 2024 UTC