I want to define a constant or variable and use it anywhere, like E_ All or$_ SERVER
Statement to define constants
Global variables can be defined in the global variable array $globals http://php.net/manual/zh/rese...
Looking at the main question, I feel that "environment variable" may be in line with the main problem. When you configure PHP server with nginx, you can add the following instructions
fastcgi_param CUSTOM_ENV_VAR "my_env_value";
After that, as long as the PHP request is accessed through nginx, it can be used in any code$_ SERVER['CUSTOM_ ENV_ Var '] to get the value you need, or add a line to fastcgi's configuration file:
After that, as long as the PHP files processed by PHP fastcgi can be accessed through getenv ('custom ')_ ENV_ Var '); to get the set value
If the subject really wants to get a similar e instead of defining it himself_ For constants like all, you need to write some C. you can create your own extension (or just find any extension that you can compile) in PHP_ MINIT_ Function uses the following macro to define its own constants
REGISTER_STRINGL_CONSTANT("MY_SITE_VERSION", "1.0", 3, CONST_PERSISTENT);
Then recompile PHP
Constant can be used everywhere, defined by define function.
Variables are not recommended to use global variables. You can use static properties of classes to achieve similar functions.
There's a way. Here we are php.ini Configure Auto in_ prepend_ Item file