How can I add const from a config file to be known from analyzer?


I have a PHP config file which contains credentials for my database. e.G.


const DB_URL = "";
const DB_PORT = 1234;
const DB_NAME = "myDB";

This file is of course not part of the application folder but on an other path which is not accessible by the Webserver.

Now I include this file in my application


require_once ('/apps/config/myconfig.php');

When I now open a connection to the database like

$con = new PDO("mysql:host=" . DB_URL . ";port=" . DB_PORT . ";dbname=".DB_NAME, ....

Intelliji is not able to recognize the constants and I get a warning.

Is there any way to tell Intelliji where to find the constants or must I live with suppressing the warnings?


When it comes to constants, it should all work not requiring any extra configuration. Could you please share a screenshot similar to mine, making the Project tool window and the two files in splits visible?


Ok, to make it more clear

My config file is not in the actual project but in an extra module because I need 4 different config files. One for my developer machine, and three for our cloud servers Dev/Stage/Prod

Now I include the files like this

So on the cloud servers the config file is in /apss/config, while on my developer machine its in a parent directory of my source directory.

If I now try to access a constant from the config file like this

It isn't recognized by IntelliJi



Thank you for the extra data. Unfortunately, I am still struggling to reproduce that.

Now I include the files like this

The PHP plugin doesn't follow require/include statements, so whether or not you are including the files doesn't matter.

What does matter is that a file where constants are defined and a file where they're used belong to the same project, be they in the same module or in different ones.

Here's a screencast that demonstrates that.

Do you think you could share a project stub that is enough for reproduction? Including the .idea directory?