[thelist] PHP User Defined Functions

Allie Micka allie at pajunas.com
Wed Jan 2 11:22:59 CST 2002


> Let's say I will never have more than 100 user defined functions.
>  To what degree would the
> difference in efficiency be for:
>
> 1. Including 100 small files at the beginning of a script
> OR
> 2. Including 1 large file that contains 100 functions (which for
> me is harder to maintain)
> OR
> 3. Including only the files for the functions I need in the
> script at the time that I need them.
> (Of my 100 or so user defined functions I may only use 5 - 10 of
> them in any given script.)

Personally, I'd be right fiesty if someone left me 100's of files to manage
and if I had to use twice the amount of code to call any single function.
And again, PHP's task of finding and reading each file is going to add a lot
of unwanted overhead.

For me, its easier to break things out into logical categories.  Each page
has something it's meant to accomplish and its easier to decide in general
what that is than to decide which functions to use right off the bat. I
would group things into logical categories such as "form validation",
"string manipulation", "getting stuff out of a database", etc.  and then
include the relevant files.  If you're processing a form, include the "form
validation" file at the top of the script and code away.  If you're doing
something database related, include the "getting stuff out of a database"
file.

It will be easier to maintain these files because as your functions become
more complex you may want to call other functions from within new functions
and you run the risk of creating a list of cascading dependencies, but if
all your similarly-related functions are in the same file they can safely
call each other without risking missing files.

In either case, DOCUMENT.  Note which functions are in which files, and
document what they do.  You can do it all externally or use something along
the lines of phpdoc.  If you're doing something nonstandard just because it
makes more sense to you, it's on your shoulders to make your intentions
clear to others.

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





More information about the thelist mailing list