Menu

Error Identifier: div.rightNonNumeric

← 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 doFoo(int $numerator, bool $flag): void
{
	$result = $numerator / $flag;
}

Why is it reported? #

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

The right-hand side operand of a division (/) is not a numeric type. PHP’s division operator expects both operands to be numeric (int or float). Using a non-numeric type such as bool, null, array, or object on the right side of a division will produce unexpected results or a TypeError in strict mode.

How to fix it #

Ensure the right-hand operand is a numeric type:

 <?php declare(strict_types = 1);
 
-function doFoo(int $numerator, bool $flag): void
+function doFoo(int $numerator, float $divisor): void
 {
-	$result = $numerator / $flag;
+	$result = $numerator / $divisor;
 }

Or convert the value to a numeric type before use:

 <?php declare(strict_types = 1);
 
 function doFoo(int $numerator, bool $flag): void
 {
-	$result = $numerator / $flag;
+	$result = $numerator / (int) $flag;
 }

How to ignore this error #

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

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

Rules that report this error #

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