>I don't know about the efficiency .. but to do it .. you can use
>function_exists() to see if a function is already defined if not include the
>file for that function before using a function.

Please check this for viability...
# the directory ./includes/ contains
#       - get_my_info.php containing the function get_my_info()
#       - and numerous other functions which may or may not be
#         needed by any particular file
#
# include at the top of each page

# function_do(FunctionName,FunctionVariables)
function function_do($f_name,$f_string){
        if (!function_exists($f_name)) {
                # function doesn't exists, needs to be included
                require('./includes/'.$f_name.'.php');
        } else {
                # function already exists, no action required
        }
        eval("\$return=$f_name($f_string);");
        return $return;
}

/*

...

*/

# when we need to run a function
# instead of...
$my_info = get_my_info('name','account');
# we would do...
$my_info = function_do("get_my_info","'name','account'");



This would check to see if the function was already called and included, and if
not, include, then run and return the result.  this would avoid having to
include explicitly any files containing functions on any page as they would all
be loaded dynamically.

Am I groking this correctly?

Original questions/requirements included below.

Dave

>----- 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
>
>
>



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

Reply via email to