php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46601 E_RECOVERABLE_ERROR for "Call to a member function on a non-object"
Submitted: 2008-11-18 08:24 UTC Modified: 2014-10-07 22:10 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:0 (0.0%)
From: bugs dot php dot net-V29nHf1_z-nsp at cvogt dot org Assigned: thekid (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.6 OS:
Private report: No CVE-ID: None
 [2008-11-18 08:24 UTC] bugs dot php dot net-V29nHf1_z-nsp at cvogt dot org
Description:
------------
Calling a method on a non-object results in a non catchable fatal error, that cannot be handled by an error_handler. It would be great if it would be a catchable fatal error instead. This would e.g. make possible to send an e-mail to the developers in case of such an error.

When using object-orientation heavily, a program bug can easily result in an uninitialized or wrongly initialized variable, currently leading to a fatal error. Being able to handle this error case would be a great improvement for quality control.

I hope the implementation of PHP allows such a change.

This request is similar to http://bugs.php.net/bug.php?id=40587 .

In case this request is rejected, please attach a short reason.

Reproduce code:
---------------
set_error_handler( create_function('$code','echo "error handler called ($code)\n";') );
$o = NULL;
$o->method();
echo "end of script\n";

Expected result:
----------------
error handler called (4096)
end of script

Actual result:
--------------
Fatal error: Call to a member function method() on a non-object

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-12 18:15 UTC] bugs dot php dot net dot nsp at cvogt dot org
There is a workaround for handling fatal errors: http://ramchel.blogspot.com/2007/02/trapping-fatal-errors-in-php.html
 [2014-10-07 22:10 UTC] thekid@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: thekid
 [2014-10-07 22:10 UTC] thekid@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

https://wiki.php.net/rfc/catchable-call-to-member-of-non-object

Fixed in PHP 7.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 30 17:01:28 2024 UTC