Put my function as default function?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a function foo(), I want all my page can call this method
without include / require

I know I can set in php.ini by setting the auto_prepend...

but this will cause overhead as every file need to prepend this file
even no call to the function,

are there any better method?

instead of writting an extension?


Re: Put my function as default function?

howachen@gmail.com wrote:
Quoted text here. Click to load it

Sure, just put a copy of the function in every file which will call it.
  That way you don't have to include it and it's available.  Of course,
you'll have dozens (or hundreds) of copies running around, but who cares?

Seriously - if you don't include the file, how is PHP supposed to know
what to execute?  Any function you're going to call must either be
defined in that file (directly or via include/require), or defined in
PHP or a PHP extension.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Put my function as default function?

Quoted text here. Click to load it

I can't understand why you don't want to include / require file with this  
function but you can make DLL file where your function will be included

Ikciu  |  gg: 718845  |  www: www.e-irsa.pl

2be || !2be $this => mysql_query();  

Re: Put my function as default function?

You are working on the assumption that it is inefficient to include() a file  
containing a function when your code never actually calls that function. The  
trick is *not* to put each function in its own file, but to group them  
together into a small number of files. That way you only have a small number  
of include()s, and the fact that you only execute a small number of those  
functions is irrelevant.

The idea that you should only include() a function's definition just before  
you want to use it is totally misguided. That takes too much code for the  
developer to type in, and *THAT* is inefficient.

The overhead of include()ing a function that you don't actually use is  
sooooooo small that you can barely measure it, so don't bother. Concentrate  
your mind on things that *really* matter.

Tony Marston

Quoted text here. Click to load it

Site Timeline