1.2.805. No Keyword In Namespace¶
PHP keywords were not allowed in namespaces’ names. As a whole, or as a part of the namespace. The syntax was relaxed in PHP 8.0.
This rule is only useful to keep compatibility with previous versions. It leads to a compilation error.
While some keywords are highly specific to PHP, such as endswitch
or __halt_compiler
, others are more common such as empty(), isset(), use, global, function…
Usage of PHP keyword was also relaxed for method’ name.
<?php
namespace if {}
namespace endswitch {}
namespace a\empty\b {}
namespace end {}
?>
1.2.805.1. Suggestions¶
Avoid supporting older PHP versions while having keywords in the namespaces
Change the namespaces to use other words than keywords
1.2.805.2. Specs¶
Short name |
Namespaces/NoKeywordInNamespace |
Rulesets |
All, Changed Behavior, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74 |
Exakat since |
2.4.9 |
PHP Version |
With PHP 8.0 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Related rule |
|
Available in |