0
votes

I have a little annoying problem on my PhpStorm IDE (Version 2017.3.4).

So I am trying to have suggestion of my constants defined on my project. But when I am trying to Ctrl + Space there is none of my define constants.

All my constant are define like this in my project :

In a file :

$configFileDir = "configfile.php";

if (file_exists($configFileDir)) {
    require_once($configFileDir);

    try {
        define('CONSTANT1', $MY_CONSTANT["CONSTANT1"]);
        define('CONSTANT2', $MY_CONSTANT["CONSTANT2"]);
        ...
    }
}

All my constants are in an array called $MY_CONSTANT loaded in the file configfile.php.

Another thing : in my project these constants are define 2 times.

What I have tried so far :

  • File / Invalidate cache
  • Changing PHP version in Preferences / Languages & Frameworks / PHP

If somebody have an idea this would be cool :) .

Solution :

To get the suggestions from the IDE, I just removed the try..catch block arround the defines instructions. After that we can get the autocompletion for these constants :) . ( Big thanks to @LazyOne )

2
If you try print_r($MY_CONSTANT["CONSTANT1"]);die; inside try block. Do you get value of the constant ?Himanshu Upadhyay
I am trying to get suggestion in my IDE my constants are well defined at runtime.Buisson
Actually I can not understand your question.Himanshu Upadhyay
When you ctrl + space on phpStorm you get suggestion from the IDE. So here when I type CONST and after CTRL + space there is no suggestions of my constants : CONSTANT1 neither CONSTANT2Buisson
Right now the reason looks to be that definition is done inside the try..catch block. Move it out of it and try that way. Also: youtrack.jetbrains.com/issue/WI-38507LazyOne

2 Answers

0
votes

I have found a solution :


To get the suggestions from the IDE, I just removed the try..catch block arround the defines instructions.

After that we can get the autocompletion for these constants.

( Big thanks to @LazyOne )

-1
votes

You can type hint PHPStorm:

<?php
/** @var CONSTANT1 constant */
define('CONSTANT1', 'test');