Menu

← Back to minus.*

Error Identifier: minus.leftNonNumeric

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 subtract(string $a, int $b): int
{
	return $a - $b;
}

Why is it reported? #

The left operand of the subtraction operator (-) is not a numeric type. PHP will attempt to coerce non-numeric values to numbers at runtime, which can lead to unexpected results or TypeError exceptions in strict mode. Only int and float types should be used in arithmetic operations.

This rule is provided by the phpstan-strict-rules package.

How to fix it #

Ensure the left operand is a numeric type before performing subtraction:

-function subtract(string $a, int $b): int
+function subtract(int $a, int $b): int
 {
 	return $a - $b;
 }

If the value is a numeric string, cast it explicitly:

 function subtract(string $a, int $b): int
 {
-	return $a - $b;
+	return (int) $a - $b;
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule [1] phpstan/phpstan-strict-rules

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.