note 42032 added to function.include
| From: | php-general at lists dot php dot net | Date: | Fri, 30 Apr 2004 02:52:18 +0000 |
| Subject: | note 42032 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69023@lists.php.net to get a copy of this message | ||
Especially in interactive applications with PHP5, with __autoload it is useful to have two locations
you want to check. Of course, we don't want errors spewing out all over the place if the first
place fails so we use a @. For instance:
<?php
function __autoload($class) {
if(!@include("$class.php")) {
@include("someotherplace/$class.php");
}
?>
However this would have undesired side effects of the included files themselves not reporting any
errors. That is, if a warning, error, etc was thrown in the included file itself, it would not be
shown. Here is my solution:
<?php
function includeNice($file) {
eval(@file_get_contents($file));
}
?>
But keep in mind, for some reason, eval() is slower than regular parsing, so it may not be good for
high-load sites.
Also note that you will not know the file that the error was on, so if you have many includes, this
may not be your best option.
include() really needs an option for this, or another function.
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42032
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42032&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42032&report=yes
Search -- http://master.php.net/manage/user-notes.php