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

Hi,

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

myconfig.php

const DB_URL = "my.url.com";
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

index.php

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?

3 comments
Comment actions Permalink

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?

https://drive.google.com/file/d/1LT1EjTJlZ9-WLm6JmBStr69s6oRw0DGB

0
Comment actions Permalink

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

 

0
Comment actions Permalink

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?

0

Please sign in to leave a comment.