Menu

← Back to pureMethod.*

Error Identifier: pureMethod.parameterByRef

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);

class Calculator
{
	/**
	 * @phpstan-pure
	 */
	public function increment(int &$value): int // ERROR: Method Calculator::increment() is marked as pure but parameter $value is passed by reference.
	{
		$value++;
		return $value;
	}
}

Why is it reported? #

A method marked as @phpstan-pure must not have side effects and must always return the same result for the same inputs. A parameter passed by reference (&$value) allows the method to modify the caller’s variable, which is a side effect. This contradicts the definition of a pure method.

Even if the method does not actually modify the referenced parameter, the mere presence of a by-reference parameter signals that the method’s contract allows mutation, which is incompatible with purity.

How to fix it #

Remove the by-reference parameter and return the computed value instead:

 <?php declare(strict_types = 1);
 
 class Calculator
 {
 	/**
 	 * @phpstan-pure
 	 */
-	public function increment(int &$value): int
+	public function increment(int $value): int
 	{
-		$value++;
-		return $value;
+		return $value + 1;
 	}
 }

If the method needs to modify the caller’s variable, it is not pure. Remove the @phpstan-pure annotation:

 <?php declare(strict_types = 1);
 
 class Calculator
 {
-	/**
-	 * @phpstan-pure
-	 */
 	public function increment(int &$value): int
 	{
 		$value++;
 		return $value;
 	}
 }

How to ignore this error #

You can use the identifier pureMethod.parameterByRef to ignore this error using a comment:

// @phpstan-ignore pureMethod.parameterByRef
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: pureMethod.parameterByRef

Rules that report this error #

  • PHPStan\Rules\Pure\PureFunctionRule [1]
  • PHPStan\Rules\Pure\PureMethodRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.