RE: [PHP-DEV] downgrade undefined function from fatal error
| From: | John Coggeshall | Date: | Sun, 15 Dec 2002 02:12:32 +0000 |
| Subject: | RE: [PHP-DEV] downgrade undefined function from fatal error | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-92477@lists.php.net to get a copy of this message | ||
There is absolutely no reason why you cannot simply include your
functions in your scripts. If you are really lazy, you can even
auto_prepend an include file.
John
>-----Original Message-----
>From: Dave [Hawk-Systems] [mailto:dave@hawk-systems.com]
>Sent: Friday, December 13, 2002 8:56 AM
>To: php-dev@lists.php.net
>Subject: [PHP-DEV] downgrade undefined function from fatal error
>
>
>reviewed and did a couple of searches on this prior to signing
>up to this particular list...
>
>Is this a reasonable consideration for changes to PHP's
>handling of undefined functions?
>
>Currently, calling a previously undefined function generates
>an E_ERROR, and halts the script as a cirtical failure meaning
>we can't handle the error as we do others (this is clearly documented).
>
>What I am not clear on is why an undefined function should
>necessarily be a fatal error with no change to code the script
>to handle the error. For example
>
><?php
>function eh($type, $msg, $file, $line, $context){
> # code to parse $msg for
>/undefined\040function:\040(.*)\(\)/,$match
> # check specified directory for the function:
> # include the file if exists (./functions/$match[1].php)
> # try to resume
> # if we can't find it, halt with die()
>}
>
>error_reporting(0);
>set_error_handler("eh");
>
>undefined_function();
>?>
>
>This would seem much more intuitive, and allow collection of
>massive amounts of sharable and accessible functions to be
>contained in shared directories, and not have to worry about
>identifying them all at the head of all pages, or including
>functionsthat would not be required.
>
>Currently as a workaround we are using the following logic;
>
><?PHP
>function func($f_name){
> if(!function_exists($f_name)){
> # function doesn't exists, needs to be included
> require('/path/to/functions/'.$f_name.'.php');
> }else{
> # function already exists, no action required
> }
> return $f_name;
>}
>
>$database=call_user_func(func('DatabaseConnect'),'var1','var2');
>?>
>
>But this results in code that isn't quite as intuitive.
>
>Thoughts? Comments? "You are nuts"?
>
>Dave
>
>
>
>--
>PHP Development Mailing List <http://www.php.net/>
>To unsubscribe, visit: http://www.php.net/unsub.php
>
>