First off, define() creates a constant which, according to PHP's own reference page for that function, can only be changed in one way -- if set to the value of another constant. You can see if it's been defined already using defined() but a constant really is an identifier to a variable who's value "cannot change during the execution of a script" as per the PHP docs on constants. There are a few magic constants such as the ever popular "__FILE__" which change based on where they're used, but a normal constant is SUPPOSED to be just that -- constant, unchanging.
This is true in PHP 5.3.2 on my system - and seems to exploit a weakness in the third parameter of the define() function which is supposed to determine case sensitivity when creating the constant. It seems if you explicitly define true (even though its the default, case insensitive) this behavior occurs. Bug?
Just because you can do this now doesn't mean you should!
So I'm saying don't use constants for things like what you're trying to do.
-jim
Jim, Sr. Web Developer You know who you real friends are when you ask them to move your furniture or paint.
Ok, was affraid of something like that. It means a complete rebuild of the system.
What I might do as a work around for the moment is put all these into a database and at the begining of the script create a definition from the results of the sql statement.
Not sure what speed implications that would have but it is a step in the correct direction whilst I trawl through all parts of the code removing any definition that should not be used in this way.
That would work, or a simple XML file, or CVS, or custom .ini file. Also, you can still generate the PHP script with constants, code a back end CONFIGURATION TOOL or utility which allows admins to create and update said file (i.e. formats suggested above or your current format), just keep the admin config and interface separate, or standalone. No changing the existing code, just extending it. A few cosmetic changes to link the admin page, and maybe store the admin password encrypted in any of said formats or methods.
-jim
Jim, Sr. Web Developer You know who you real friends are when you ask them to move your furniture or paint.
Bookmarks