Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ohffs's avatar
Level 50

PHP Storm - can't find any classes

I decided to give PHP Storm another try for a big legacy codebase as it looked like it would offer a lot of nice tools to refactor the code. However... as with most things in IT, it doesn't seem to be working right. No matter how many things I tick or un-tick in the preferences it can never resolve a class that comes about as something like :

// config.php
define('CLASSES', './classes/');

// some_other_bit_of_crappy_old_code.php
require(CLASSES . 'something.php');
$thing = new Something();
$thing->doTheDamnedThing();

And PHP Storm can't resolve Something() and thus any method definitions like doTheDamnedThing() - which makes it about as much use as Notepad (only much slower).

I can see various threads online about changing the code to use __DIR__ in front of all the require's or otherwise altering the code - but the whole point of using PHP Storm is I'm trying to track down all these methods, code flows etc without modifying literally 100's of files and 1000's of require() statements. If I wanted to do that I'd just stick with sublime. I've tried generating a composer classmap for everything inside classes/ too - to no avail.

Anyway - just wanted to know if anyone has some kind of 'Ah! You just tick XYZ in the preferences!' that I've missed before I drag php storm to the trashcan as I've done many times before...

0 likes
5 replies
jimmck's avatar

@ohffs Hey. Storm is great at looking codebases, but you have to be patient. First and foremost is that anything marked as Red or broken may not be so to the installed PHP interpreter. You need to set your active/excluded project directories. You need to set the exact PHP setting you will use in the Settings/Language/PHP settings. Need to see how you setting things up and the code examples.

For example to bootstrap Laravel and use Vendor autoloader, I do this...

 <?php
use App\MyGlobals;
use App\lib\myutils\apputils\GDate;
use App\lib\myutils\utils\Pack;
use App\lib\myutils\apputils\mongo\MongoConnection;
use App\lib\myutils\apputils\mongo\MongoDocument;
use App\lib\nba\NBATeam;

require dirname(__DIR__) . '/vendor/autoload.php';
require dirname(__DIR__) . '/bootstrap/app.php';
1 like
ejdelmonico's avatar

@ohffs I agree with @jimmck. It works great but the tweaking required for libraries and binaries takes a bit of getting used to. There is specific docs for Laravel projects to help. And, a tip...if you keep getting import warnings, make sure your directories - resources are properly defined or excluded. See the docs for that. oh, don't forget to define root directory or it won't find anything.

1 like
ohffs's avatar
Level 50

Thanks @ejdelmonico & @jimmck :-) I tried again and added the base folder as both the project root and 'resource root' and now it can find things - though it does keep complaining about functions returning void for reasons that escape me! But much improved - thanks both of you! :-)

ejdelmonico's avatar

@ohffs I have always had complain about a void return in the comments. However, if it's complaining about things you don't want it to, then the settings for the language will help. Also, don't forget to enable node and es2015 for a Laravel project so it can find everything.

ohffs's avatar
Level 50

@ejdelmonico I'll try and go through the settings - I was kind of hoping it would have 'sane defaults' though, which in this case it doesn't seem to. Hey ho. It's not a laravel project (it's an old PHPv4 codebase) so there's less to worry about on the JS/CSS/gulp/whatever side of things - which is one silver lining I guess ;-)

Please or to participate in this conversation.