php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26966 error handler causing problems
Submitted: 2004-01-19 12:43 UTC Modified: 2004-01-23 03:12 UTC
From: vania at pandorasdream dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2004-01-19 (dev) OS: *
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: vania at pandorasdream dot com
New email:
PHP Version: OS:

 

 [2004-01-19 12:43 UTC] vania at pandorasdream dot com
Description:
------------
I am having difficulties with either trapping errors, the try/catch or the __get/__set functionality.  I've tried to simplify the case, but I can't get it down any further than what I have posted at my site.  

I am finding that when I access a protected variable from outside the class, the __get and __set are never called.  Instead, an error appears, "Fatal error: Cannot access protected property second::$c in e:\PHP\projectcodewiki\www\test\noprepend\testgetter.php on line 25".  

This error is not getting caught in the error handler.  I have tried this with error_reporting(E_ALL & E_STRICT) and error_reporting(E_ALL).  I note in #12136 that this problem is noted for errors associated with methods/functions.  It was noted that this was an "Unrecoverable" error.  However, since this class of error will not occur until the line is run (note that "a value is 4" actually appears), the error never gets caught until the user reaches the code.

If this behavior resulted in a set_error_handler catchable code, it would allow for graceful feedback to the user and behind-the-scenes notification to the webmaster.  It does not leave the app in an unstable state, and might also be something that would be handled by a __get/__set.  Please consider making this throw an exception or being caught by the set_error_hanlder code block.

Thanks,

Reproduce code:
---------------
<?php
function myErrorHandler ($errno, $errstr, $errfile, $errline)
{
    $exceptn .=  "Custom Error";
    throw new exception($exceptn, $errno, $errfile, $errline);
}

class second
{
    protected $c;
    public $a;

    public function __construct()
    {
        $this->c= 4;
        $this->a= 4;
    }
}

$child = new second;

try
{
    //error_reporting(E_ALL & E_STRICT);
    $old_error_handler = set_error_handler("myErrorHandler");
    print "a value is ".$child->a.".<br>";
    print "c value is ".$child->c.".<br>";
}
catch (exception $e)
{
    print $e->getMessage();
}
?>

Expected result:
----------------
a value is 4.

Custom Error

Actual result:
--------------
a value is 4.

Fatal error: Cannot access protected property second::$c in e:\PHP\projectcodewiki\www\test\noprepend\customerror.php on line 27

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-19 14:10 UTC] vania at pandorasdream dot com
Addendum:  In reviewing the note for 12136, I also noticed that it was in reference to PHP4.0.6.  With PHP5 and it's try/catch handling, it seems that it is even more critical to allow for some way to have these types of issues be caught, even if that means using set_error_hanlder.  

Is is possible to add E_FATAL, perhaps, in addition to E_STRICT to allow for BC, while still allowing error handling to be customized with try/catch?  If so, I would assume it, like E_STRICT would not be covered by E_ALL.

Just thinkin'.

thanks again,

Vania
 [2004-01-23 03:12 UTC] sniper@php.net
Fatal errors are fatal errors. Program execution ENDS at those.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 21:01:33 2024 UTC