How can I change PHP constants?

A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script (except for magic constants, which aren't actually constants). A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.

The name of a constant follows the same rules as any label in PHP. A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thusly: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

From: Constants (PHP mamual)


Constants are constants and therefore cannot be changed. If you want to change the server constants such as allow_url_fopen, that is the host's reponsibility, ask them. If you want to change them in PHP, use variables

UPDATE

In case the truth is what Corbin says and you want to modify them in installation, you would want to do the following: 0. Change constant values to sg. like %%constant1. 1. read the code into a variable. 2. Let the user set the variables. 3. Use str_replace on all of them like str_replace("%%constant1",$_POST["value1"],$configfile). 4. Put $configfile as a content of a file.

UPDATE 2

For your own CMS only, I suggest the following: store all constants in one file, so you will need to edit one file only. And perhaps than the previous solution could work for an easier editing, but IDK if it is worth the time.


No. They're constants, as in "constant - that which is permanent or invariable" (Wiktionary). Once they're defined, there is no way to change them. To quote The Fine Manual, section Constants:

[a constant's] value cannot change during the execution of the script.

Tags:

Php

Constants