php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69841 Feature: Catchable "call to a member function of a non-object" is not working
Submitted: 2015-06-15 16:41 UTC Modified: 2015-06-15 16:50 UTC
From: davelhs03 at yahoo dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.0alpha1 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: davelhs03 at yahoo dot com
New email:
PHP Version: OS:

 

 [2015-06-15 16:41 UTC] davelhs03 at yahoo dot com
Description:
------------
In the RFC (https://wiki.php.net/rfc/catchable-call-to-member-of-non-object) set_error_handler was suppose to catch calls to methods on a non-object.  I'm not experiencing that when I use PHP7 Alpha1 (http://windows.php.net/downloads/qa/php-7.0.0alpha1-nts-Win32-VC14-x86.zip) on Windows 7.  I tried it on the command line and via the built in web server.  I can catch the exception if I do a try and catch (EngineException $e) block, but not with the error handler.

//This Works:
$x= null;
try{
var_dump($x->method());
}
catch (EngineException $e)
{
echo 'caught the exception';
}

Test script:
---------------
set_error_handler(function($code, $message) {
  var_dump($code, $message);
});
 
$x= null;
var_dump($x->method());
echo "Alive\n";

Expected result:
----------------
int(4096)
string(50) "Call to a member function method() on a non-object"
NULL
Alive

Actual result:
--------------
Fatal error: Uncaught EngineException: Call to a member function method() on nul
l in C:\PHP7\scripts\test.php:6
Stack trace:
#0 {main}
  thrown in C:\PHP7\scripts\test.php on line 6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-15 16:50 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2015-06-15 16:50 UTC] nikic@php.net
The linked RFC has been superseded by https://wiki.php.net/rfc/engine_exceptions_for_php7, which does not allow handling these using set_error_handler. You must either catch the exception or use set_exception_handler.
 [2015-06-15 16:57 UTC] davelhs03 at yahoo dot com
nikic,

Thanks for the quick reply and answer!

Anyway you can put that comment in the wiki so others don't fall into looking at out-dated documentation.

https://wiki.php.net/rfc/catchable-call-to-member-of-non-object
 [2015-06-15 17:11 UTC] nikic@php.net
@dacelhs03: Sure, I've added a note at the top.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC