php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63538 "Call to undefined function" should be catchable
Submitted: 2012-11-16 10:13 UTC Modified: 2015-03-21 20:41 UTC
Votes:17
Avg. Score:3.9 ± 1.3
Reproduced:10 of 11 (90.9%)
Same Version:2 (20.0%)
Same OS:5 (50.0%)
From: indeyets@php.net Assigned: yohgaki (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.5.0alpha1 OS: any
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: indeyets@php.net
New email:
PHP Version: OS:

 

 [2012-11-16 10:13 UTC] indeyets@php.net
Description:
------------
At the moment, call to undefined function results as "Fatal error". On the other hand, it can be easily handled programmatically either by including required file or just defining function dynamically.

Test script:
---------------
<?php

set_error_handler(function($errno , $errstr){
    if (strpos($errstr, 'Call to undefined function there_is_no_me()') === 0) {
        function there_is_no_me()
        {
            echo "Here am I!\n";
        }
    }
});

there_is_no_me();


Expected result:
----------------
Here am I!

Actual result:
--------------
Fatal error: Call to undefined function there_is_no_me()

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-23 19:37 UTC] lubosdz at hotmail dot com
What about function_exists() ?

set_error_handler(function($errno , $errstr){
    if (!function_exists('there_is_no_me')) {
        function there_is_no_me(){
            echo "Here am I!\n";
        }
    }
});

lubosdz
 [2012-11-29 10:15 UTC] bensor987 at neuf dot fr
I think it is better to add a function autoloader, instead of just catching this error.
 [2012-11-29 10:37 UTC] indeyets@php.net
bensor987 that's a separate issue. autoloader is a specific solution, while 
ability to handle such error is more generic
 [2013-04-30 11:28 UTC] jevon at jevon dot org
In particular, this would allow developers to handle undefined functions in batch scripts and the like. Since one can catch undefined classes (through an autoloader), undefined class methods (through __call() and __callStatic()) and undefined variables (through set_error_handler()), why shouldn't we be able  to catch undefined functions?
 [2013-06-28 07:14 UTC] yohgaki@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: yohgaki
 [2013-06-28 07:14 UTC] yohgaki@php.net
Old PHPs were able to catch E_ERROR.

I always think E_ERROR should be able to catch by user defined error handler. The 
reason why E_ERROR made uncatchable is there were many users that shot their own 
foot by not terminating execution. However, user should be able to own foot by 
catching E_ERROR.

I think PHP should give chance user to display 500 page.
 [2013-06-28 08:27 UTC] yohgaki@php.net
This is a PoC patch for catching E_ERROR/E_PARSE.

https://github.com/yohgaki/php-src/compare/master-catch-e_error
 [2015-03-21 20:41 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2015-03-21 20:41 UTC] nikic@php.net
It's possible to catch this as of PHP 7, see https://wiki.php.net/rfc/engine_exceptions_for_php7.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC