|
Posted by Henk Verhoeven on 06/26/06 17:09
Extending the solution of Bob:
function callWithAutoInclude($functionName, $parameters) {
if (!function_exists($functionName)) {
require($functionName.'.php');
}
return call_user_func_array($functionName, $parameters);
}
the following:
callWithAutoInclude('somefunction', array($param1, $param2) );
will then be the equivalent of:
somefunction($param1, $param2);
Greetings,
Henk Verhoeven,
www.phpPeanuts.org
Janwillem Borleffs wrote:
> Bob Stearns wrote:
>
>>Is there an option in php to do a 'require xxx.php' if, when a
>>function call to xxx is encountered, it is not defined? It would look
>>in all the standard places.
>>
>
>
> The best you can do is to test if the function exists and include its
> definition when it doesn't:
>
> if (!function_exists('somefunction')) {
> require 'funcdef.php';
> }
>
> You can also use require_once/include_once to prevent the file being
> included more than once, which causes an error because of the re-definition.
>
>
> JW
>
>
[Back to original message]
|