Menu

← Back to logicalAnd.*

Error Identifier: logicalAnd.leftNotBoolean

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(string $s, bool $b): void
{
	$result = $s and $b;
}

Why is it reported? #

This error comes from phpstan-strict-rules. It reports that the left side of an and operator is not a boolean value. Strict boolean comparisons require both sides to be of type bool to avoid subtle bugs caused by PHP’s type juggling. In the example, $s is a string, which will be implicitly coerced to bool.

How to fix it #

Explicitly convert the value to a boolean:

 function doFoo(string $s, bool $b): void
 {
-	$result = $s and $b;
+	$result = ($s !== '') and $b;
 }

Or use a boolean variable:

-function doFoo(string $s, bool $b): void
+function doFoo(bool $a, bool $b): void
 {
-	$result = $s and $b;
+	$result = $a and $b;
 }

How to ignore this error #

You can use the identifier logicalAnd.leftNotBoolean to ignore this error using a comment:

// @phpstan-ignore logicalAnd.leftNotBoolean
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: logicalAnd.leftNotBoolean

Rules that report this error #

  • PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule [1] phpstan/phpstan-strict-rules

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.