|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48622 Invalid error reporting with __toString() method
Submitted: 2009-06-20 22:03 UTC Modified: 2018-09-29 19:38 UTC
Avg. Score:4.6 ± 0.6
Reproduced:13 of 14 (92.9%)
Same Version:6 (46.2%)
Same OS:7 (53.8%)
From: woody dot gilk at kohanaphp dot com Assigned: dmitry (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.2.10 OS: Mac OSX 10.5
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.
Block user comment
Status: Assign to:
Bug Type:
From: woody dot gilk at kohanaphp dot com
New email:
PHP Version: OS:


 [2009-06-20 22:03 UTC] woody dot gilk at kohanaphp dot com
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:

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__;



set_error_handler(array('test', 'error_handler'));


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 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-20 22:05 UTC] woody dot gilk at gmail dot com
Here is a copy of the test script:
 [2009-06-22 19:18 UTC] woody dot gilk at kohanaphp dot com
To add a little more information here, I should be able to do this:

    echo $object.$foo;
catch (ErrorException $e)
    // Trap the E_NOTICE from $foo being undefined
    echo 'error occurred';

However, because an E_FATAL is incorrectly triggered, it is impossible 
to do so.
 [2016-07-14 11:12 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2018-09-29 19:38 UTC]
-Status: Assigned +Status: Duplicate
 [2018-09-29 19:38 UTC]
Marking as a duplicate of bug #53648, which has more discussion on this issue.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 23:01:29 2024 UTC