#48622 [Opn]: Invalid error reporting with __toString() method
| From: | woody dot gilk at gmail dot com | Date: | Sat, 20 Jun 2009 22:05:18 +0000 |
| Subject: | #48622 [Opn]: Invalid error reporting with __toString() method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-138576@lists.php.net to get a copy of this message | ||
ID: 48622
User updated by: woody dot gilk at gmail dot com
Reported By: woody dot gilk at gmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: Mac OSX 10.5
PHP Version: 5.2.10
New Comment:
Here is a copy of the test script: http://gist.github.com/133305
Previous Comments:
------------------------------------------------------------------------
[2009-06-20 22:03:30] woody dot gilk at gmail dot com
Description:
------------
When using a custom error handler, it is possible to make PHP trigger
an
E_FATAL by concatenating an object with a __toString() method together
with a variable that is not set.
Tested in 5.2.9 and 5.2.10.
Reproduce code:
---------------
<?php
class test {
public static function error_handler($code, $error, $file = NULL,
$line = NULL)
{
// This error is not suppressed by current error reporting settings
throw new ErrorException($error, $code, 0, $file, $line);
}
public static function run()
{
$object = new self;
echo $object.$foo;
}
public function __toString()
{
return __CLASS__;
}
}
error_reporting(E_ALL);
set_error_handler(array('test', 'error_handler'));
test::run();
Expected result:
----------------
PHP Fatal error: Uncaught exception 'ErrorException' with message
'Undefined variable: foo' in php_bug.php:15
Stack trace:
#0 php_bug.php(15): test::error_handler()
#1 php_bug.php(29): test::run()
#2 {main}
thrown in php_bug.php on line 15
Actual result:
--------------
PHP Fatal error: Method test::__toString() must not throw an exception
in
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48622&edit=1