Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell the PhpStorm IDE that a constant exists?

Tags:

phpstorm

The IDE (PS-117.65) is complaining that some of constants aren't defined.

I've defined them in a loop in another file. Can I put a doc comment at the top of this file to inform it about the constants? The usual /** @var and @global syntax doesn't seem to work for constants.

like image 804
mpen Avatar asked Mar 29 '12 17:03

mpen


1 Answers

There is no known to me PHPDoc comment to do that.

But you can "fake" them -- create some const.php file and place it anywhere in a project (you can even place it in separate folder outside the project and attach it as External Library or as separate Content Root).

In this file -- define those constants with in a normal way: define("CONST_NAME", "value"); The "value" part can be anything (as long as types are matching -- useful for inspections/code analysis) -- it really depends where those constant will be used (e.g. if they are used in include/require statements, then it may be beneficial to have some real (or close to it) values there).

like image 63
LazyOne Avatar answered Sep 24 '22 19:09

LazyOne