To your first question, I'm sure it can only increase efficiency.
To the second, think the other way around possibly...
Within your script, do the following (or something along these lines):
Pull a list of your includes directory into an array ($all_functions in my
example)

/**
 $file is the script itself, i.e. if your script was myScript.php,
 $file would be /path/to/myScript.php, as if you were opening it from a
shell
**/

fopen($file,'r');
while ($filerow = fgets($file,1024))
{
     /** Parse for functions here, somewhat indepth logic) **/

    if (in_array($function,$all_functions) &&
!in_array($function,$included_functions))
    {
        $included_files[] = $function;
        include("/path.to/".$function.".php");
    }
}


Alternatively, don't have it as functions, use require()
require() gets executed ever time it is read, as if it were an actual part
of your script. Plus it uses whatever is defined in the script's existing
memory space (works great for chopping down the # of lines in huge while
loops)

Matt
----- Original Message -----
From: Dave [Hawk-Systems] <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, December 11, 2002 10:40 AM

Subject: [PHP] Automatic include of files containing functions


> On a few sites we have used a master include or function file containing
all the
> unctions required for the site...  Some of these function files may
contain
> 30-40 functions and some pages use only 1 function from the file.
>
> Would like to be a little more dynamic in our approach of this, and have
started
> moving all the functions into their own files...  for example moving
connectdb()
> from the functions.php file to a connectdb.php or connectdb.inc file.
>
> Then for any particular php page, we would pull in only the functions that
we
> need for that particular page.  From a script/function management
perspective
> this would be ideal.
>
> Questions//
>
> What would this do as far as speed and efficiency (having to load 4 or 5
> includes/requires rather than one larger include that has 25 functions
that
> aren't needed or used)?
>
> Then the hard one...
>
> Is there a way to have the PHP script dynamically pull in the required
include
> files?  for example, have a function at the top of each page to include
any
> files required as a result of functions that exist in the script...  ie:
this
> page uses abc() 123() and so it include/require ./includes/abc.php and
> ./includes/123.php which contain the appropriate functions.
>
> OR
>
> is there an easier way to manage what is becoming an over abundance of
functions
> for particular sites.
>
> Have gotten in the habit of creating a function for anything I have to do
more
> than 1 or 2 times on seperate pages just to speed and simplify code from a
> design and readability point of view.
>
>
> Appreciate any comments.
>
> Dave
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to