Hi, I haven't seen anything like that implemented yet. I have my functions logically grouped/organised into files... I only include the file when needed. Some files (like my string functions and DB functions) are auto-prepend (a php.ini directive) auto-included into every script, which does save me some time.
However, it occurs to me that there COULD be a way to implement what you want... whether it's worth the grief or not is a different discussion altogether :) For starters, you can check whether a function has been defined using function_exists(). If it doesn't exist, you could then include() it, assuming that you have one function per file, and each file named the same as the function, or with decent naming conventions. There are two functions which can call your user defined function call_user_func_array() (use an array to pass multiple arguments) or call_user_func() aparently for single arguments. I haven't used either of these. In psuedo code, here's what i'm thinking: <? function theWrapper($targetFunction,$args) { if(!function_exists($targetFunction)) { $file = "functions_lib/{$targetFunction}.func"; if(file_exists($file)) { include($file); } } $result = call_user_func_array($targetFunction,$args); return $result; } ?> so, let's say I have a function called foo, saved as a file foo.func in the /functions_lib/ directory <? function foo($animal,$name,$color) { return "I have a {$animal} named {$name}, and it is {$color}"; } ?> I could the call foo() thru theWrapper() <? $args = array('cat','muffins','black'); echo theWrapper('foo',$args); ?> *Totally* untested code, but in theory this should echo "I have a cat named muffins, and it is black" Now, this still needs a LOT of work. theWrapper() needs lots of error handling code... i haven't allowed for missing functions/files, missing arguments, or anything else... I guess this was more of a "proof of concept"... perhaps something to get you started? Or perhaps something to make you say "nahhhhh, too difficult" :) Justin on 10/01/03 9:15 AM, Brian T. Allen ([EMAIL PROTECTED]) wrote: > Hi, > > This may exist, but I haven't been able to find it, and I think it would > be REALLY helpful and convenient. > > The idea is this: > > When you write a script and call a function: > > <?php > > $whatever = previously_uncalled_function("one","two"); > > ?> > > PHP would automatically look for a file named > "previously_uncalled_function" in your /include/functions/ directory. > > This would eliminate a LOT of include() and require() calls (or at least > make them automatic) in a script. The function would only get read in > if it was used. > > This would be very convenient. When you create a new function you drop > it in that directory (with a very specific, unique name, of course), and > it can immediately be called anywhere in the site. And, you only incur > the disk IO to read it when its used for the first time in a script. > > The 3 things I want to avoid are: > > 1) Explicitly including every function, every time it's needed. > 2) Disk IO of including a function when it's not needed. > 3) Taking the easy route and including a file with a bunch of functions > when most won't get called. > > Does this already exist, or is this a good idea (if not, any reasons > why)? I personally would love to see it implemented if it isn't > already. > > Thanks, > Brian Allen > [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php