简体   繁体   中英

Is it possible to define a PHP class server wide?

What I am asking is something like declaring environment variable in Apache for PHP like

SetEnv SITE_MAIN_DIR "/var/www/www.mydomain.com/"

That I can access anywhere in the site and it works great.

echo $_SERVER['SITE_MAIN_DIR']

Does PHP have similar to this for global classes so that I do not have to use include /dir/class.php ;

class::function($string); without using include?

You can use getenv()

echo getenv(SITE_MAIN_DIR);   

https://www.php.net/manual/en/function.getenv.php

But I would consider using an autoloader.

PHP 7.4 有一个名为opcache preloading的新功能,也许这就是您正在寻找的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM