-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
DisallowDefineSniff.php
adds and error (!) everytime a define
is encountered and the reason (which I fully agree to) is that const
should be preferred.
However, in PHP const
is not allowed inside condition blocks, because those are only checked at runtime. For example a snippet like the following is invalid and throws a parse error:
if (!defined('FOO')) {
const FOO = true;
}
Another limitation of const
is that it does not accept expression as constant name. For example following is also invalid and throws a parse error:
foreach(['FOO', 'BAR'] as $name) {
const $name = true;
}
So there are cases in which the usage of define
is really necessary, and pretty much it turns out to be anytime the level of const
token is not 1
.
If you agree, I could send a PR for this.
Metadata
Metadata
Assignees
Labels
No labels