I have several functions that I wrote and I use regularly on my servers, is there a way I can add them to the core so I don't have to include them from external files?
I am running PHP5
I have several functions that I wrote and I use regularly on my servers, is there a way I can add them to the core so I don't have to include them from external files?
I am running PHP5
You could add your libraries as a PEAR extension. Then you could add it to your local PEAR repository. Pear is added to the default include path in php.ini. Then you can just use "pear install myextension" on your machines.
If these are C functions you interface with in php (php extensions) then you can do something similar with PECL.
I've done this before.. it's a fairly involved process, but not too bad. This article at zend.com should tell you everything you need to know:
http://devzone.zend.com/node/view/id/1021
edit: I should add that there are better ways to achieve the essence of what you're trying to do. Remember that doing this will further clutter up PHP's (already very cluttered) namespace. You're probably better off just making a global include file that has all of your most commonly used functions that you include wherever you need it.
edit2: Upon rereading your original question, you said you don't want to do that, but I still think it's probably the best way. But best of luck to you with the extension route.
Why exactly is it so hard to include the files where you need them?
I suppose the auto_prepend_file PHP.ini directive could work. But it's not really recommended.
If you got autoload, you can move the functions as static methods of a class like My_Functions.
Or for dividing it into more files you can use My_Functions_Math. Then you will only need to load the functions you need. And with autoload you don't have to worry about including files.
You cant autoload namespace functions, so if you want to use autoload the functions have to be static methods in a class. But you can use namespace to make it easier to fx replace the class in the future and/or shorten the long class name. Example:
use My\Functions\Math as Math;
Math::calcThis($i);