1

I'm always using a function to write to a log file, but this function is defined in a file among many other things that I don't need to include.

I was wondering, is it possible to define a function somewhere inside php to make it available without the need to include the source file? Sort of like how I can just use echo or die, or isset. Could I create my own function to use it this way?

Thank you.

  • Here is a nice answer to a question about autoloading functions: http://stackoverflow.com/a/4737275/669073 – netiul Jun 14 '13 at 07:07

3 Answers3

4

No. To do that, you'll have to write a PHP extension in C. Any PHP code will always need to be included explicitly one way or another.

PHP has the option to always automatically include a file at the beginning though: http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file

deceze
  • 510,633
  • 85
  • 743
  • 889
1

Actually, you need to make a module with your function. Other ways:

  1. make autoload. http://www.php.net/manual/en/language.oop5.autoload.php

  2. put only this function to other file and include it everytime you need.

Andrej Bestuzhev
  • 674
  • 6
  • 10
0

you can add you log class in set_include_path path or add this function to pear library class

Saurabh Chandra Patel
  • 12,712
  • 6
  • 88
  • 78