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.

4

3 回答 3

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

于 2013-06-14T07:07:30.090 回答
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.

于 2013-06-14T07:07:06.733 回答
0

您可以将您添加log classset_include_path路径中或将此功能添加到pear库类

于 2013-06-14T07:11:09.423 回答