php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40587 Attempt to call undefined function gives a fatal error instead of recoverable
Submitted: 2007-02-21 23:03 UTC Modified: 2007-02-21 23:20 UTC
From: mathiasrav at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.1 OS: WinXP
Private report: No CVE-ID: None
 [2007-02-21 23:03 UTC] mathiasrav at gmail dot com
Description:
------------
If you try to call an undefined function, PHP raises an E_ERROR and crashes - not a catchable E_RECOVERABLE_ERROR.
This isn't a problem for web-related scripts, but for maintainence/shell-like scripts, this can be a help. I have a script with an idle-loop that calls (includes) module-files, and if a change to one of these has a typo, all socket connections and the like are killed.

Reproduce code:
---------------
<?php
function returntrue(){return true;}
seterrorhandler('returntrue', E_RECOVERABLE_ERROR);
qweasd();
echo 'Carrying on...';
?>

Expected result:
----------------
The call to qweasd() should return false or null. If the programmer has made the script able to recover from calls to unknown functions, he must have written code that can tell the difference between the return code from a known and an unknown function.

Actual result:
--------------
The script halts.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-21 23:06 UTC] mathiasrav at gmail dot com
A little change to the description-section - PHP doesn't crash, it simply halts script execution. The *script* "crashes".
 [2007-02-21 23:20 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2011-11-14 21:03 UTC] matteosistisette at gmail dot com
If this is not a bug, this is a HUGE design flaw that MUST be fixed, so is there 
any difference?

If calls to undefined functions were detected at compile time, this would be 
fine. But since they are detected at runtime, you simply can't debug your code 
from such errors if a misspelled call happens to be within an if clause. Not 
being able to catch these errors means not being able to debug them, which 
means, the language's designed is flawed.

A "Fatal error: call to undefined function" SHOULD be a E_RECOVERABLE, not a 
E_ERROR.
Anything that happens at runtime and can conceivably be recovered from, must be 
a E_RECOVERABLE.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC