Menu

Error Identifier: plus.rightNonNumeric

← Back to plus.*

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 add(int $a, bool $flag): int
{
	return $a + $flag;
}

Why is it reported? #

The + operator in PHP performs arithmetic addition on numeric types or array union on arrays. Using a non-numeric, non-array type on the right side of + is a type error that leads to unexpected behaviour or a runtime fatal error.

This rule is part of phpstan-strict-rules.

How to fix it #

Ensure the right operand is a numeric type:

-function add(int $a, bool $flag): int
+function add(int $a, int $b): int
 {
-	return $a + $flag;
+	return $a + $b;
 }

Or cast the value explicitly:

 function add(int $a, bool $flag): int
 {
-	return $a + $flag;
+	return $a + (int) $flag;
 }

How to ignore this error #

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

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

Rules that report this error #

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