Pavlo N
Pavlo N

Reputation: 83

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?

Upvotes: 3

Views: 519

Answers (1)

nibra
nibra

Reputation: 4028

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.

Upvotes: 6

Related Questions