1.2.1453. Yield Usage

Usage of generators, with yield keyword.

Yield was introduced in PHP 5.5, and is backward incompatible.

<?php

function prime() {
    $primes = [2, 3, 5, 7, 11, 13, 17, 19];
    foreach($primes as $prime) {
        yield $prime;
    }
}

?>

See also Generator Syntax, Deal with Memory Gently using “Yield” in PHP and Understanding PHP Generators.

1.2.1453.1. Specs

Short name

Php/YieldUsage

Rulesets

All, Appinfo, CE

Exakat since

0.8.4

PHP Version

With PHP 5.5 and more recent

Severity

Time To Fix

Precision

Very high

Features

yield, yield-from

Available in

Entreprise Edition, Community Edition, Exakat Cloud