I think that it only finds constants that are created:
define('NAME', 'value');
In case if we do it that name is variable/argument of function, this warning is triggered. I think about such use cases:
1) function defineX($name, $value) { return define($name, $value);} defineX('NAME', 'value');
2) $i = 'NAME'; define($name, 'value');
Use of undefined constant 'NAME' PHP(PHP0415)
- Edited
GroM Thank you for the feedback,
yes, you're right. The editor recognizes only statically defined constants:
const NAME = 0;
- `define('NAME', 0);
We can additionally recognize constants defined in doc comments, i.e. /** @const NAME */ although @const
is not a valid keyword.
In general, it is recommended to add a dummy file (for example .ide-constants.php
) containing define(...)
for all your dynamic constants.