Menu

← Back to generator.*

Error Identifier: generator.nonIterable

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

/** @return \Generator<int> */
function doFoo(): \Generator
{
	$value = 42;
	yield from $value;
}

Why is it reported? #

The expression passed to yield from is not iterable. yield from requires an iterable argument such as an array, a Traversable, or another Generator. In the example above, $value is an int, which cannot be iterated.

How to fix it #

Pass an iterable expression to yield from:

 <?php declare(strict_types = 1);
 
 /** @return \Generator<int> */
 function doFoo(): \Generator
 {
-	$value = 42;
-	yield from $value;
+	$values = [42];
+	yield from $values;
 }

How to ignore this error #

You can use the identifier generator.nonIterable to ignore this error using a comment:

// @phpstan-ignore generator.nonIterable
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: generator.nonIterable

Rules that report this error #

  • PHPStan\Rules\Generators\YieldFromTypeRule [1] [2]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.