PhpStorm does not highlight an error when parent class defined below



The following code will produce a fatal error because PHP won't see b class but PhpStorm won't highlight it, I wonder why

class a extends b {}

class b {}


Hi there,

>I wonder why

Because in general PhpStorm does not care where the class declaration is located.

Same story if it's located in another file and you forgot to reference/load that file (e.g. if you still using manual include/require instead of class autoloading) -- IDE does not know how you are loading classes.

I would agree that if they both declared in the same file then IDE might produce some notice ... but considering the rarity of such situation especially nowadays when it's common rule to keep 1 class per file ... rather unneeded work from devs. Feel free to submit a ticket to Issue Tracker if so desired.


@Andriy is correct.

There's File | Settings | Editor | Inspections > PHP | Code Style | Multiple classes declarations in one file inspection that can be enabled to help with such cases.


Please sign in to leave a comment.