Is there anyway in php, by which we can define our own magic constants, which value could vary throughout the program and how to define variables with the SUPER GLOBAL SCOPE
.
Defining your own magic constants in php?
505 Views Asked by mega6382 At
3
There are 3 best solutions below
0

While you can declare global variables, superglobals are limited to those found in PHP. You might want to keep your data as $_SESSION['mysuperglobal']
, althou I suggest more elaborated patterns like a config-singleton, a registry or dependency injection.
0

You cannot define magic constant w/o building own flavour of PHP. But you can mimic this by putting all your "magic" define()
s in separate file and including it in each of your script you can use auto_prepend_file
config directive. Still, if you think you need something like this, the I'd try to rethink that approach. Whenever "magic" or "global" things comes to play, it's rather indication of need of refactoring.
Just add the variable as an Apache environment variable:
You could set that in
httpd.conf
,apache2.conf
, or.htaccess
.PHP should then be able to access it via one or more of the following methods: