From: vania at pandorasdream dot com
Operating system: Windows XP
PHP version: 5CVS-2004-01-19 (dev)
PHP Bug Type: Class/Object related
Bug description: error handler causing problems
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 bug report at http://bugs.php.net/?id=26966&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26966&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26966&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26966&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26966&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26966&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=26966&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=26966&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26966&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26966&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26966&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26966&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26966&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26966&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26966&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26966&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26966&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26966&r=float