1.2.598. Invalid Constant Name¶
There is a naming convention for PHP constants names.
According to PHP’s manual, constant names, ‘ A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.’.
Constant, must follow this regex : /[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
.
In particular when defined using define() function, no error is produced. When using const
, on the other hand, the name must be valid at linting time.
<?php
define('+3', 1); // wrong constant name!
echo constant('+3'); // invalid constant access
// This won't compile, with a syntax error.
// const 3A = 3;
?>
See also Constants.
1.2.598.2. Connex PHP features¶
1.2.598.2.1. Suggestions¶
Change constant name
1.2.598.2.2. Specs¶
Short name |
Constants/InvalidName |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |