Search code examples
joomlaphpstormundefined

PhpStorm - undefined class in Joomla project


I want to use PhpStorm on Joomla project but I can not use "Go to Class Declaration" (Ctrl+B) on main Joomla classes. For example JFactory::getApplication().

But with my own functions in custom plugin that option works great.

What it can be wrong there?

  • I have Joomla support plugin.
  • I have docblock plugin.
  • I tried invalidate caches.

Solution

  • Legacy code

    You only need that to work on legacy code. With the introduction of namespaces, most classnames have changed.

    JFactory is a now non-existent class - it has been removed from the core. For compatibility's sake, a class alias is provided at runtime, so PHP can find the new class instead. PhpStorm (and other IDEs) don't know about those aliases (there are a lot more of them).

    Stubbing

    To solve the problem, Joomla provides a stub, that tells the IDE where to find the new class. Just run

    $ php build/stubGenerator.php
    

    This will generate a stubs.php file in your project's root directory with the proper information.

    New code

    For new code, don't use those old classnames - use their new name instead. The new classnames make it much more likely, that your new code will run on Joomla! 4.0.