Using environment variables in PhpStorm

Hi all,

I am a total PhpStom noob, so please forgive my novice level.

My PHP application makes use of custom environment variables, such as $_SERVER["APPLICATION_ENV"]. These variables are set in Apache etc.

My question: How can I set them, so that PhpStorm is aware of them?


require($_SERVER["APPLICATION_PATH"] . '/application/bootloader.php');

PhpStorm can not find this required file, as it does not know of the environment variable APPLICATION_PATH. Maybe moving to $_ENV might be a solutioin?!?

Any help would be greatly appreciated.
1 comment
Comment actions Permalink

Hi there,

You cannot -- PhpStorm does static file analysis and therefore $_SERVER etc cannot be retrieved .. and currently you cannot manually assign any values for such array for further evaluation by PhpStorm.

In general -- this is not great approach (in terms of app portability). You better find another/better idea to include files.

For example, if your website has single point entry (e.g. every request routed via index.php) then you can declare some constant there that will contain some path .. and then use it in every include statementinstead of your  $_SERVER ['CONFIG_VAR'].

If this is the ONLY way you can run your app (for whatever reason), then I can only suggest turning off appropriate inspection in PhpStorm (Settings | Inspections) for the whole project or suppress warning just for that line (via Alt+Enter when light bulb is shown).


Please sign in to leave a comment.