Menu

← Back to logicalOr.*

Error Identifier: logicalOr.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);

function doFoo(bool $a, bool $b): void
{
	$result = $a or $b; // ERROR: Unused result of "or" operator.
}

Why is it reported? #

The or keyword has lower precedence than the = assignment operator. This means the expression $result = $a or $b is parsed as ($result = $a) or $b, not as $result = ($a or $b). The assignment of $a to $result happens first, and then the or $b part is evaluated but its result is discarded.

This is almost always a mistake where the developer intended to assign the result of the logical OR to the variable.

How to fix it #

Use || instead of or to get the expected precedence:

 <?php declare(strict_types = 1);
 
 function doFoo(bool $a, bool $b): void
 {
-	$result = $a or $b;
+	$result = $a || $b;
 }

Or add explicit parentheses to clarify the intended grouping:

 <?php declare(strict_types = 1);
 
 function doFoo(bool $a, bool $b): void
 {
-	$result = $a or $b;
+	$result = ($a or $b);
 }

How to ignore this error #

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

// @phpstan-ignore logicalOr.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: logicalOr.resultUnused

Rules that report this error #

  • PHPStan\Rules\DeadCode\NoopRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.