I am working on creating my own custom CMS in PHP manually, and I have a few constants that I defined. Is there an easy way to change constants? I thought about using something like fopen(), and then changed it, but I never used the file system functions.
fopen()
A constant is an identifier (name) for a simple value. As the name suggests, the value cannot change at run time (except for magic constants, which are not actually constants). By default, a constant is case sensitive. By convention, constant identifiers are always capitalized., PHP. , , . , : [A-Za-Z_\x7f-\XFF] [A-Za-z0-9_\x7f-\XFF] *
A constant is an identifier (name) for a simple value. As the name suggests, the value cannot change at run time (except for magic constants, which are not actually constants). By default, a constant is case sensitive. By convention, constant identifiers are always capitalized.
, PHP. , , . , : [A-Za-Z_\x7f-\XFF] [A-Za-z0-9_\x7f-\XFF] *
from: http://php.net/manual/en/language.constants.php
. , allow_url_fopen, , . PHP,
UPDATE
, , , : 0. sg. %%constant1. 1. . 2. . 3. str_replace , str_replace ( "%% constant1", $_ POST [ "value1" ], $configfile). 4. $configfile .
%%constant1
2
CMS : , . , , , IDK, .
. , " constant - , " (). , . The Fine Manual, :
[] script.
.
in PHP, but only if you have the runkit extension installed. However, I must question why you're even defining a constant if you need to change it. It would no longer be a constant once changed and it appropriate to use constants in your context if it needs to be changed. You may want to consider making it a global variable if it needs to be accessible in other functions or parts of your code, or write proper code by: Passing the data as parameters to a function, then returning the manipulated values (if coding in a procedural fashion). Set the value in a class' property, then access the value using $this within your class (if coding in an OO fashion).
, .
, , . , :
define('ROOT', '/some/path'); echo ROOT; // echo /some/path define('ROOT', '/some/other/path'); // gives an error echo ROOT; // gives /some/path (if there were no error $root = '/some/path'; echo $root; // echo /some/path $root = '/some/other/path'; echo $root; // echo /some/other/path
, script, , CMS, . hes .
, :
define(DB, ''); define(USER, ''); define(PASS, ''); define(HOST, '');
And he wants to create scripts that populate these constants with data so that they can be used in the CMS.