Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 246
Pavlo N Avatar asked Jan 28 '26 04:01

Pavlo N


1 Answers

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.

like image 155
nibra Avatar answered Jan 31 '26 11:01

nibra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!