logo
podcast Podcast
get help Get Unstuck

How to ignore a specific PHPStan error

And communicate even more clearly with your team

Joel Clermont
Joel Clermont
2025-06-17

A little over a year ago, PHPStan introduced a new concept of "error identifiers" to be more specific when marking a line of code as ignored.

For example, take this chain of Eloquent method calls.

/** @phpstan-ignore method.notFound */
$result = $this->currentClient($request)
    ->someScope()
    ->someOtherScope()
    ->withTrashed()
    ->get();

Without the error identifier, I wouldn't immediately know what error was being ignored. But now, I can see that PHPStan can't find one of the methods on that line. This is a huge improvement!

While this is a nice improvement, I am still left wondering which one (or more) of those 5 method calls are the actual problem.

PHPStan does not yet allow us to get more precise and ignore just one specific method, but there is a catch-all ability to add additional text to the ignore comment, without breaking PHPStan's analysis:

/** @phpstan-ignore method.notFound (withTrashed) */

Anything in the parentheses following our error identifier will be ignored by PHPStan, but it will be visible to anyone reading the code.

I like to use that space to call out which methods are having the problem, to improve communication with my team.

One other nice thing about PHPStan is that it will throw an error if I try to ignore something that no longer is causing an error.

So if PHPStan or Larastan fixes this issue in a future release, I will be notified that I can remove this ignore comment, making my code just a bit cleaner over time. Very nice!

Here to help,

Joel

P.S. Have you tried to add Larastan to your project, but found it too difficult? We can help guide you through the process, and find the right balance of strictness for your team.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.