Robert Eisele schreibt in seinem Blog xarg.org immer mal wieder über aktuelle PHP Themen oder eigene Entwicklungen in Sachen PHP. Im neusten Beitrag stellt er seine PHP Extension defcon vor. Mit dieser können in PHP globale Konstanten angelegt werden.
So können zum Beispiel Datenbankparameter einheitlich gespeichert und verwaltet werden:
# Database Config
string DBHOST = "localhost";
string DBUSER = "root";
string DBPASS = "";
string DBNAME = "test";
Praktisch um die Konstanten global verfügbar zu haben. Und das PHP weit! Seine Worte dazu:
There are certainly many possibilities to create a global config-file for your web project. You could create a global configuration file for your defines, which you have to include in every file. Better is an automatic include by the auto_prepend_file directive in your php.ini.
The problem here is the word* „include“. For every include you need hard drive access and have the parse- and cast-overhead for the directives. Someone could say that you could install an op-cache and the problem is cleared. Okay thats quite right. Some good op-code caches do also mmap variables and constants. But not in every case an op-cache is appropriate. Consequently it’s difficult to have constants available everytime and above all global.