#26966 [Opn]: error handler causing problems

From: Date: Mon, 19 Jan 2004 19:10:36 +0000
Subject: #26966 [Opn]: error handler causing problems
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-53593@lists.php.net to get a copy of this message
ID: 26966 User updated by: vania at pandorasdream dot com Reported By: vania at pandorasdream dot com Status: Open Bug Type: Class/Object related Operating System: Windows XP PHP Version: 5CVS-2004-01-19 (dev) New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2004-01-19 12:43:02] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26966&edit=1

« previous php.bugs (#53593) next »