In my project I have MVC architecture and in class Application I define some constants like AUTH and AUTH_ID.
I can use this constants in other files - controllers, etc, IDE recognizes them as defined constants and I can move to constant declaration by pressing Ctrl+B, but in files outside Application.php (where my class defined, where constants defined) I do not have them in suggestion list.
So my question is: Is there any way to get my constants throughout all project in suggestion list?
Hi there,
It works fine for me here in my projects.
1) Did it worked before and now stopped? Try "File | Invalidate Caches..."
2) Do you use namespaces?
3) How those constants are defined?
4) You do not have them in "suggestion list" .. but you you actually type the full name manually -- does it work (I mean: does PhpStorm shows an error; can it navigate to declaration in such case)?
5) Please provide some sample project (as simple as possible, if it is yours ..or full one if it is open source) that reproduces the issue. So far I have no real clue why it does not work for you.
Hello, Thank you for answer
1) Never wodked. Doesn't help.
2) No
3) With define instruction
4) Everything is works, except suggestion
5) Example attached
Thanks for the project.
Keith is correct -- it is WI-11390.
If you do not want to change your code -- use workaround suggested (it is for IDE only).
If possible -- change your code (will be beneficial for all):
A) define constants in global namespace (I mean: outside of class). For example:
<?
define('AUTH_USER', 'Pavel');
class myClass {
function __construct() {
}
}
A "trick" with include/require will also work just fine, e.g. (based on your example)
lib.php
<?
class myClass {
function __construct() {
require "./defines.php";
}
}
defines.php
B) Maybe you can convert it into class constants:
lib.php
index.php
C) Or just class variables (so you can alter them as required) -- be it real variable .. or magic one (just treat them as constants in your code -- do not assign new value anywhere else). But this means you have to change even more code.
Oh, this is sad. I found this solution on stack overflow, but it means that both constants will shown in "go to declaration" menu. Well, it's better than nothing -)