3

As a php developer i need to instantiate classes all the time. By doing this i need to include or require these classes.

I am used to Netbeans IDE where i can easily use the "fast import" option (alt+shift+i). It allows me to use include or require to import classes.

I'm trying Sublime for now and it's been great until now, but the lack of this option makes me upset.

Is there any solution for Sublime Text to import php classes?

Pablo S G Pacheco
  • 2,550
  • 28
  • 28
  • There isn't anything out of the box. And I also did a quick package control search and didn't find anything. You could make a custom plugin, however, I don't know how you would look up what file needs to be included without just searching every file everywhere. I could understand in a project maybe setting a path, but it would have to index all the files to find classes which could get large for something like a framework. And how would it know the path? Just make it relative to the current file? – Jonathan Kuhn Oct 16 '14 at 17:57
  • Make it relative to the current file would be just good enough. I think Netbeans Fast Import works like this – Pablo S G Pacheco Oct 16 '14 at 18:10
  • 1
    Have you considered writing an [autoloader](http://php.net/manual/en/function.spl-autoload-register.php) to scour your directories for the files and include them at runtime? – Crackertastic Oct 16 '14 at 18:49
  • 1
    I'm not sure if autoloaders have some issues with code cache, like opcache or memcache, so i prefer not to rely on them – Pablo S G Pacheco Oct 16 '14 at 19:08
  • @Crackertastic I got addicted to autoloaders now :) – Pablo S G Pacheco Jul 07 '15 at 14:28
  • 1
    @PabloKarzin Yes, autoloaders are quite handy. If you end up using Composer in one of your projects they have a nice way of working up an autoloader for your project and all of the dependent packages that you can import with a single `require` statement. – Crackertastic Jul 07 '15 at 15:50

1 Answers1

7

PHP companion package is what you need, you can import classes, insert namespaces, go to method definition with these package. Search for php companion in package control if you have that installed or visit the package repo for more details https://github.com/erichard/SublimePHPCompanion

Nehal Hasnayeen
  • 1,203
  • 12
  • 23