Menu

← Back to plus.*

Error Identifier: plus.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 doFoo(): void
{
	$null = null;
	$result = $null + 5;
}

Why is it reported? #

The + operator in PHP is intended for numeric arithmetic (or array union). When a non-numeric value such as null, an object, or a non-numeric string is used on the left side of the + operator, PHP will attempt implicit type coercion, which is error-prone and usually indicates a bug.

In the example above, null is used on the left side of the + operator, which PHP silently coerces to 0.

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

How to fix it #

Ensure the left operand is a numeric type (int, float, or numeric string):

 <?php declare(strict_types = 1);
 
-function doFoo(): void
+function doFoo(int $value): void
 {
-	$null = null;
-	$result = $null + 5;
+	$result = $value + 5;
 }

Or explicitly convert the value to a number first:

 <?php declare(strict_types = 1);
 
 function doFoo(?int $value): void
 {
-	$result = $value + 5;
+	$result = ($value ?? 0) + 5;
 }

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.