Cannot find declaration to go to (PHPStorm)

Answered

PHPStorm 2016.3

Mac OS 10.9.5

 

My old copy of PHPStorm 8, and the newly installed 2016.3 can't find declarations in a couple of my projects.

I've tried Invalidate Cache/Restart a couple of times, but no luck.

 

14 comments

Could you please show us the project structure and the actual code?

0

Thanks very much for your reply Eugene. In this example, the file where the function is declared is in the same directory as where the function is called. The feature does work when the declaration is in the same file.

 

0

1) So .. where were you trying to click on? on "tag_m" or on "getTaggedDepartments"? (most likely the 2nd one based on screenshot)

2) What PhpStorm knows about that "tag_m" field (what it will show if you invoke "View | Quick Documentation" on it)?

0

Andriy

1) Correct, the screen shot is accurate, I was clicking on "getTaggedDepartments"

2) Here is what I get when I click on tag_m and choose Quick Documentation

 


 

0

Based on your new screenshot (especially the full size view) I can say that this behaviour is correct.

PhpStorm does not know what "tag_m" field is (what type). If you look at your screenshot and IDE carefully you will see some grey wavy underline under tag_m -- if you hover your mouse over it you should see warning/notice "this field is declared dynamically" or stuff like that.

So yeah -- IDE does not know what tag_m and therefore cannot detect where to take you when you Ctrl+Click on getTaggedDepartments().

 

How is your tag_m is defined? Do you have something like "private/protected $tag_m;" somewhere in this/parent class? or is it handled by some magic __get/__set ?

  • If it's something like "private $tag_m;" -- add such PHPDoc comment before that line:"/** @var MyClass */"  (where MyClass should be the correct class)
  • If it's some magic handled by __get/__set -- add this kind f line into class level PHPDoc comment: "@property MyClass $tag_m"
  • (all without double quotes obviously)

https://phpdoc.org/docs/latest/references/phpdoc/tags/var.html

https://phpdoc.org/docs/latest/references/phpdoc/tags/property.html

 

0

So, my first reaction to all of that Andriy is that the feature *was* working....

I'l parse through your response and check as much as I can.

 

0

Ok, so yes, the grey wavy line is there under tag_m, and it says that the field is accessed via magic method (though I have no idea what that means.)

 

tag_m is a class that is an extension to a CodeIgniter model:

class Tag_m extends MY_Model
{

It is loaded into the item model like this:

$this->load->model('tag_m');

The class declaration also has the grey wavy line, and it says "Other declaration of class Tag_m exists" -- this is not actually the case though. I believe that the IDE sees a symlink to the file as a second declaration. Is there a way to get PHPStorm to ignore the symlinks?

 

0

>and it says that the field is accessed via magic method (though I have no idea what that means.)

It means that this field is created at run time so IDE does not know anything about it (what type it is) when you edit the code (as it only does static analysis).

https://youtrack.jetbrains.com/issue/WI-1174 -- you may check this and related tickets (mainly comments) for typical ways on how others solving such issues (you will see  `@property` suggestions similar to what I did above).

 

>It is loaded into the item model like this:

Yes -- it's loaded during run time only and since IDE does not have any special support for CodeIgniter framework it does not know what "$this>load->model('tag_m');" does and what "$this->tag_m" field is now.

 

>and it says "Other declaration of class Tag_m exists" -- this is not actually the case though. I believe that the IDE sees a symlink to the file as a second declaration.

It's correct -- when you try Ctrl+Click on such class name (e.g. in "new MyClass()") it will show popup with choices what declaration to use/where to go.

 

>Is there a way to get PHPStorm to ignore the symlinks?

You may exclude such 2nd file from the project -- e.g. mark folder as Excluded .. or mark individual file as Plain Text (all via right click menu in Project View panel).

Right now IDE treats all sym links/hard links/junction points as duplicate/separate files, e.g.

1

Thanks for your explanation Andriy. I've added the property declaration, excluded the symlink, and Invalidated caches, but still no luck jumping to the function declaration. Have I missed something?

 

0

Well ...

1) from your screenshot -- the Tag_m class is still underwaved -- check what it says (crazy idea but maybe your project has more than 2 classes with that name (yet another symlink etc)??) Try doing a project wide search for "class Tag_m" ("Find in Path" action)

2) That "@property" should be added into the class where it is used (I guess Item_m.php ??). Basically, "@property Tag_m $tag_m" means -- "this class will have public $tag_m field" .. so it should be placed in the class from previous screenshots.

1

There was another Tag_m class, in a different name space. I deleted it, and there is no longer a underwave in the Tag_m class declaration

I moved the @property to the top of the Item_m file. Now, when I hold down the command key, the tag-> is hyperlinked. Clicking it takes me to the top of the Item_m. Clicking on the tag_m method still tells me that the declaration is not found. Invalidated caches and restarted as well.

0

Screenshots please. What PhpStorm thinks about tag_m in $this->tag_m now (View | Quick Documentation)?

I'm not familiar with neither CodeIgniter (have not used it myself, only seen the framework code few years ago) or your current project .. so have no idea where getTaggedDepartments() is defined. I would assume in Tag_m class ?

0
$this->tag_m->getTaggedDepartments($result);

Yes, in CodeIgniter, that means that getTaggedDepartments is a method of the tag_m class.

 

PHPStorm seems to not be aware of the Tag class, outside of the @property declaration in Item_m:

 

 

0

I think that I got it:

 

/**
* @property \Tag_m $tag_m
*/

Tag_m is in the global name space, while Item_m is in a different name space. Adding \ to the property declaration seems to have fixed it.

 

Thanks Andriy!

0

Please sign in to leave a comment.