Menu

← Back to parameterByRef.*

Error Identifier: parameterByRef.type

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 Foo
{
	public function doFoo(string &$p): void
	{
		$p = 1;
	}
}

Why is it reported? #

A value assigned to a by-reference parameter does not match the parameter’s declared type. In the example above, the parameter $p is declared as string, but an int value is assigned to it inside the method.

Since the parameter is passed by reference, the assigned value will be visible to the caller. Assigning a value of the wrong type can lead to type errors in the calling code that expects the variable to remain a string.

How to fix it #

Assign a value that matches the parameter’s declared type:

 class Foo
 {
 	public function doFoo(string &$p): void
 	{
-		$p = 1;
+		$p = 'value';
 	}
 }

Or, if the parameter intentionally receives a different type, use a @param-out PHPDoc tag to declare the output type:

 class Foo
 {
+	/** @param-out int $p */
 	public function doFoo(string &$p): void
 	{
 		$p = 1;
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Variables\ParameterOutAssignedTypeRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.