Menu

← Back to generator.*

Error Identifier: generator.sendType

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<mixed, mixed, int, mixed> */
function innerGenerator(): \Generator
{
	$value = yield 'hello';
}

/** @return \Generator<mixed, mixed, string, mixed> */
function outerGenerator(): \Generator
{
	yield from innerGenerator();
}

Why is it reported? #

When using yield from to delegate to another generator, the TSend type of the delegated generator must be compatible with the TSend type of the delegating generator. The TSend type parameter (third in Generator<TKey, TValue, TSend, TReturn>) defines what type of values can be sent into the generator via Generator::send().

In the example above, innerGenerator() expects int values to be sent into it, but outerGenerator() accepts string values. When outerGenerator() delegates to innerGenerator() via yield from, any string value sent to the outer generator would be forwarded to the inner generator, which expects int.

How to fix it #

Make the TSend types compatible between the delegating and delegated generators:

 <?php declare(strict_types = 1);
 
-/** @return \Generator<mixed, mixed, string, mixed> */
+/** @return \Generator<mixed, mixed, int, mixed> */
 function outerGenerator(): \Generator
 {
 	yield from innerGenerator();
 }

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.