Constants identification

Hello,

I am using a custom function to declare some global constants, this function simply declares the constant if it does not exist.

I am getting some trouble with PhpStorm because it is not identifying my constants. I would like to do it manually but it seems there is no way.

So I have 2 problems, or 2 possible missing solutions :

  1. PhpStorm identifies automatically / manually a constant function.
  2. PhpStorm takes care about a phpdoc tag declaring manually a global constant.

Example:

defifn('DEV_VERSION', !IS_WEB);
Typing DEV_ , ctrl + space, no suggestion.

 

Is there currently a solution I missed ? Else, could it be a planned feature ?

0
6 comments

No, this should work fine.

Could you please attach a screenshot that would show this problem in your code? 

0

@Loenix

Please provide the actual code to copy-paste next time... It's no fun to re-type it manually.

function defifn($name, $value)
{
if (defined($name)) {
return false;
}
define($name, $value);
return true;
}

 

After looking through like 200 tickets (https://youtrack.jetbrains.com/issues/WI?q=define+constant) I have found these:

0

Sorry ... That was not the purpose...

 

It seems that https://youtrack.jetbrains.com/issue/WI-9270 is close but it has no valid solution.

Or should I create fake code to declare all constants ? It will be ugly...

0

Hello, It was 3 years ago and I am still having the same issue. Constants declared by a custom function are not recognized and we are unable to write phpdoc to declare it. I tried @const and @constant, but this is not working.

0

@Loenix

Seems like the best way here is still the same: define them in a normal way in a separate PHP file that will be used by the IDE only. Not the best way of course but it's better than nothing.

P.S. WI-42979 ticket is asking for the ability to define constants (their values?) via PHPDoc...

0

Please sign in to leave a comment.