Menu

← Back to staticMethod.*

Error Identifier: staticMethod.resultUnused

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

class Foo
{
    public function doFoo(): void
    {
        \DateTimeImmutable::createFromFormat('Y-m-d', '2024-01-15');
    }
}

Why is it reported? #

The static method call on a separate line has no side effects, and its return value is not used. This means the call is pointless – it computes a result that is immediately thrown away, without changing any state.

PHPStan detects this by checking whether the method has known side effects. Methods on immutable objects like DateTimeImmutable are pure and produce no side effects, so calling them without using the result serves no purpose.

How to fix it #

Assign the return value to a variable or use it in an expression:

 <?php declare(strict_types = 1);
 
 class Foo
 {
     public function doFoo(): void
     {
-        \DateTimeImmutable::createFromFormat('Y-m-d', '2024-01-15');
+        $date = \DateTimeImmutable::createFromFormat('Y-m-d', '2024-01-15');
     }
 }

If the method call is truly unnecessary, remove it:

 <?php declare(strict_types = 1);
 
 class Foo
 {
     public function doFoo(): void
     {
-        \DateTimeImmutable::createFromFormat('Y-m-d', '2024-01-15');
     }
 }

How to ignore this error #

You can use the identifier staticMethod.resultUnused to ignore this error using a comment:

// @phpstan-ignore staticMethod.resultUnused
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: staticMethod.resultUnused

Rules that report this error #

  • PHPStan\Rules\DeadCode\CallToStaticMethodStatementWithoutImpurePointsRule [1]
  • PHPStan\Rules\Methods\CallToStaticMethodStatementWithoutSideEffectsRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.