note 28668 added to function.require
| From: | Satisfied at rack1 dot php dot net | Date: | Mon, 20 Jan 2003 11:07:48 +0000 |
| Subject: | note 28668 added to function.require | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42419@lists.php.net to get a copy of this message | ||
Subject: Require/Include via function calls
I tried to create a "smart" include function on my own such as follows:
function api_load($handle) {
require 'mySpecialAPIPath/'.$handle.'.php';
}
This was suppose to let me just:
api_load('bbs');
api_load('html');
BUT THIS WILL NOT WORK.
The require function is used inside a function call. In other words, all the content of the required
file is put INSIDE the api_load() function, not OUTSIDE as a regular require call would. This causes
problems with name spaces.
I settled for the following:
function objApi($handle) {
return 'obj/api/'.$handle.'.php';
}
include objApi('html');
include objApi('whois');
Maybe someone has something better.
peace.
--
http://www.php.net/manual/en/function.require.php
http://master.php.net/manage/user-notes.php?action=edit+28668
http://master.php.net/manage/user-notes.php?action=delete+28668
http://master.php.net/manage/user-notes.php?action=reject+28668