Const variables, show path

Hello, can you help me please, how to let PHPSTorm known a path to files when using variables, constants ?
For example i set:
require_once $SERVER['DOCUMENT_ROOT']."/_const/base.php;
and this works, but PHPStorm highlights word '_const' like, Path '_const' not found. But how can i fix this ? 

Comment actions Permalink

Hi there,

It's not possible -- currently PhpStorm cannot not evaluate what $_SERVER['DOCUMENT_ROOT'] is (such info is only available during runtime) --

Your only solution right now is to either disable this inspection completely (it does not do much anyway) -- Settings | Inspections | PHP | General | Unresolved Include
.. or just suppress it for that line only:

  • Alt+Enter while cursor standing on problematic place
  • Arrow right
  • Suppress for statement


Final result would be:

/** @noinspection PhpIncludeInspection */
require_once $_SERVER['DOCUMENT_ROOT']."/_const/base.php;

BTW -- I assume you have typo there as it should be $_SERVER instead of  $SERVER

Comment actions Permalink

Okay, i got it. Thank you ;)
Yeap, sorry, my mistake - not "$SERVER", but $_SERVER .


Please sign in to leave a comment.