Constant Redefinition¶
<?php
const A = 1;
const A =1; // warning!
class X {
const B = 2;
const B = 2; // fatal error
}
It is possible to specify several identical global constant definition: PHP reports a warning, and ignores the second definitions.
On the other hand, a duplicate class constant definition is a fatal error, and fails the compilation phase.
The difference of behavior may be linked to the level of consistence that PHP can achieve: global constants needs an application wide check for name unicity, while class constants can be checked while compiling a class.
Yet, it might be worth looking into leveling both errors, to avoid hard to find bugs.
See Also¶
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026