|  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
Avg. Score:3.9 ± 1.3
Reproduced:10 of 11 (90.9%)
Same Version:2 (20.0%)
Same OS:5 (50.0%)
From: Assigned: yohgaki (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.5.0alpha1 OS: any
Private report: No CVE-ID: None
 [2012-11-16 10:13 UTC]
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:

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


Expected result:
Here am I!

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


Add a Patch

Pull Requests

Add a Pull Request


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

 [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]
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]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: yohgaki
 [2013-06-28 07:14 UTC]
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]
This is a PoC patch for catching E_ERROR/E_PARSE.
 [2015-03-21 20:41 UTC]
-Status: Assigned +Status: Closed
 [2015-03-21 20:41 UTC]
It's possible to catch this as of PHP 7, see
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 01 20:01:24 2021 UTC