php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #21759 custom handlers for parse errors
Submitted: 2003-01-19 18:18 UTC Modified: 2003-01-20 12:10 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: nospam at 1111-internet dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.2.2 OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nospam at 1111-internet dot com
New email:
PHP Version: OS:

 

 [2003-01-19 18:18 UTC] nospam at 1111-internet dot com
I'd love to see a mechanism in PHP similar to the Apache ErrorDocument directive to allow the custom handling of pre-execute-time errors (such as most parse errors), since these errors precede and thus usurp set_error_handler(), leaving you otherwise stuck with only slightly modifiable PHP error messages.

The error values error_type_str, buffer, error_filename, error_lineno, and type (from main/main.c) could be passed to the handler script as $_SERVER["error_type_str"], et. al. to allow the handler to use them dynamically - perhaps even passing them to the same custom error handler function that got spurned the first time around, i.e.:

------------------------------------

<?php
// /bad_script.php

include_once("my_function_lib.inc");
// contains valid function my_custom_error_handler()

set_error_handler("my_custom_error_handler");
// and would all be fine and good to catch errors such as:

$x=1/0;

// except

xxxxx
xxxxx
// causes a parse error, which gets processed before
// my_custom_error_handler() is available

exit;
?>

------------------------------------

# php.ini or .htaccess
# (... other directives)
php_error_document = '/error_handler_script.php'
# (other directives ...)

------------------------------------

<?php
// /error_handler_script.php - to the rescue

include_once("my_function_lib.inc");
// same as above, but now we

my_custom_error_handler($_SERVER["error_type"],
    $_SERVER["error_type_str"],
    $_SERVER["error_filename"],
    $_SERVER["error_lineno"]);
// to do directly what we were unable to do via
// set_error_handler() the first time around

exit;
?>

------------------------------------

I've seen a few posts from people looking for something like this, and this strikes me as the most elegant way of going about it. I've also read replies to similar posts and I don't see this particular approach having been suggested before. As to "(t)he (php-dev) decision ... that parse errors are preventable" - I definitely agree, and will add that they're easier to prevent as it gets easier to find and fix them. That's what this idea is trying to accomplish - I want my error handler on my development server to display the source code at and around the error so that I can more quickly find and fix the problem.

Looking at the PHP source I'm guessing it wouldn't be terribly difficult to implement this... you'd just need to make sure you break out of the loop that would otherwise be caused if the error handler script itself has a parse error in it...

I'm using 4.2.2 but I noticed that your change log as of 4.3.0 doesn't mention anything like this, so I assume I'm not re-proposing the wheel here.

Thanks.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-20 00:51 UTC] derick@php.net
This won't be implemented as discussed on the dev list some weeks ago.
 [2003-01-20 11:34 UTC] nospam at 1111-internet dot com
If I was to develop this myself, to whom might I submit my updates for consideration for inclusion in a future release?
 [2003-01-20 12:10 UTC] derick@php.net
That was done before, and I dont think it will have much chance of being included.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 15 00:01:35 2024 UTC