Menu

← Back to paramOut.*

Error Identifier: paramOut.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);

/**
 * @param-out int $p
 */
function foo(mixed &$p): void
{
	$p = 1;
	$p = 'str'; // ERROR: Parameter &$p @param-out type of function foo() expects int, string given.
}

Why is it reported? #

A by-reference parameter has a @param-out PHPDoc tag declaring the type that the parameter should have when the function returns. The value assigned to the parameter inside the function body does not match the declared @param-out type.

The @param-out tag is a contract with callers: it guarantees that after the function call, the referenced variable will have the specified type. Assigning a value of an incompatible type breaks this contract.

How to fix it #

Ensure the assigned value matches the declared @param-out type:

 <?php declare(strict_types = 1);
 
 /**
  * @param-out int $p
  */
 function foo(mixed &$p): void
 {
 	$p = 1;
-	$p = 'str';
+	$p = 2;
 }

Or update the @param-out type to reflect the actual values being assigned:

 <?php declare(strict_types = 1);
 
 /**
- * @param-out int $p
+ * @param-out int|string $p
  */
 function foo(mixed &$p): void
 {
 	$p = 1;
 	$p = 'str';
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Variables\ParameterOutAssignedTypeRule [1]
  • PHPStan\Rules\Variables\ParameterOutExecutionEndTypeRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.