[thelist] PHP User Defined Functions

Allie Micka allie at pajunas.com
Wed Jan 2 10:13:30 CST 2002


> Does anyone know of a way to call a User Defined PHP function
> that is in file separate from the
> current script WITHOUT doing an include on the file that contains
> the function.

Well, you could manually type in the code before using it each time.  The
PHP processor HAS to know about the function sometime during that page
execurion before you go using it.  It can't read minds!

One thing you can try is to put "php_value auto_prepend_file
name_of_file_that_contains_a_bunch_of_includes" into an .htaccess file, and
each script will benefit from the fact that you've already done all the
includes you need.

This might get hairy and I recommend that you group multiple functions into
shared files.  PHP won't let you re-declare functions so there shouldn't be
any problem with name collision in the files, and if you're really concerned
about having the same function names appear in different files you can
prepend the function names themselves.

For instance, if you create a group of functions for validation you can
prepend your function names with something like 'val' , such as valEmail or
valDate.

You would then only need to include the validation library with a single
include file to use all the validation functions.  I think you'll find this
approach much more manageable and efficient.  It's certainly more efficient
to  avoid typing in all those include lines and its generally more efficient
for PHP to have declared functions that you're not using than to ask it to
include yet another file for each new function call.

PHP itself acts this way.  Imagine how inefficient the coding and processing
of any PHP script would be if you had to include a file for each of its
1000s of native functions!

thanks,
Allie Micka
pajunas interactive, inc.
reusable web components and hosting
http://pajunas.com





More information about the thelist mailing list