Autocomplete for classes when class name is modified by autoload Follow
Hi,
I'm working on a big project where autoload changes the name of classes by adding "Core" to the class name.
autoload :
require($root_dir.$classname.'Core']);
Is there a way to tell PhpStorm to recognize those classes?
Please sign in to leave a comment.
Hi there,
I'm sorry .. but I do not understand what is the actual problem is.
Generally speaking PhpStorm does not care how your autoloader works -- it works with class names as they are declared
file1.php
class MeowCore {...}
file2.php
load_class("Meow");
...
$v = new MeowCore();
That's exactly my point: classes are not declared as they are called.
classes are declared with "Core":
class FrontControllerCore extends Controller { ... }
But there are instancied without "Core":
$controller = new FrontController();
And it works because the autoload creates dynamically the right instanciation using eval():
eval(($class_infos->isAbstract() ? 'abstract ' : '').'class '.$classname.' extends '.$classname.'Core {}');
I think I can create some PHP file for the IDE containing lines like this:
class FrontController extends FrontControllerCore() {};
But I suppose there may be a better way to do it.
Yes. That's exactly how it's done for other frameworks that use similar idea (e.g. FuelPHP: https://github.com/antitoxic/.fuelphp-phpstorm-workaround or https://gist.github.com/huglester/3860656 )
No. For example existing ticket WI-9029 for aforementioned FuelPHP is marked as "backlog", which means "maybe one distant day in the future, since usable workaround exist"
Thank you. I created this file and have placed at the root of my project (see attached file).
It works fine for autocomplete but everytime it is opened (with a Ctrl+Click on a classname), PhpStorm compeletely freezes. I suppose it is because it contains to much class definitions (320 lines).
Attachment(s):
__ide_classes.php.zip
I guess this is possible (to freeze/slow-down when opening such file).
What you can try to do: