|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-01-19 14:10 UTC] vania at pandorasdream dot com
[2004-01-23 03:12 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 21:00:02 2025 UTC |
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