开发者

PHP global include?

I have a seperate PHP file I include that has a several important functions on it. I also have a file called variables.php which I include into each function so I can call some important variables too. Is there a way to just call variables.php at the top of the page, instead of inside each function manually? I just thought it would be easier 开发者_开发问答if there was a way to do like a 'global' include or something.


You can set auto_prepend_file in the INI or .htaccess file to automatically include a file.


Well, if they are constant variables (AKA they don't change) you can define a constant instead

define("CONSTANT_NAME", "constant_value");

Or as of PHP5.3

const COSTANT_NAME="constant_value";

Then you can access them in every function

function test(){
    echo CONSTANT_NAME;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜