Menu

← Back to logicalXor.*

Error Identifier: logicalXor.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
{
	$r = $a xor $b;
}

Why is it reported? #

The result of the xor operator is not being used. The xor operator in PHP has a very low precedence – lower than the assignment operator =. This means the expression $r = $a xor $b is actually parsed as ($r = $a) xor $b, which assigns $a to $r and then discards the result of the xor operation.

This is almost certainly not the intended behaviour. The same precedence issue applies to the and and or operators.

How to fix it #

Use parentheses to disambiguate the logic:

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

Or use the ^ operator instead, which has higher precedence and works as expected with booleans:

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

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\DeadCode\NoopRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.