Menu

Error Identifier: div.leftNonNumeric

← Back to div.*

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 divide(bool $flag, int $denominator): float
{
	return $flag / $denominator;
}

Why is it reported? #

This error is reported by phpstan/phpstan-strict-rules.

The left operand of a division operator (/) is not a numeric type (int or float). Division is an arithmetic operation that only makes sense with numeric values. Using a non-numeric type like bool, array, object, or null on the left side of a division indicates a logic error.

In the example above, $flag is a bool, which is not a valid numeric operand for division.

How to fix it #

Use a numeric value as the left operand:

 <?php declare(strict_types = 1);
 
-function divide(bool $flag, int $denominator): float
+function divide(int $numerator, int $denominator): float
 {
-	return $flag / $denominator;
+	return $numerator / $denominator;
 }

Or convert the value to a numeric type before dividing:

 <?php declare(strict_types = 1);
 
 function divide(bool $flag, int $denominator): float
 {
-	return $flag / $denominator;
+	return (int) $flag / $denominator;
 }

How to ignore this error #

You can use the identifier div.leftNonNumeric to ignore this error using a comment:

// @phpstan-ignore div.leftNonNumeric
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: div.leftNonNumeric

Rules that report this error #

  • PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule [1] phpstan/phpstan-strict-rules
Theme
A
© 2026 PHPStan s.r.o.