1.2.497. Generator Cannot Return

Generators could not use return and yield at the same time. In PHP 7.0, generator <https://www.php.net/`generator>`_ can now use both of them.

<?php

// This is not allowed until PHP 7.0
function foo() {
    yield 1;
    return 'b';
}

?>

1.2.497.1. Suggestions

  • Remove the return

1.2.497.2. Specs

Short name

Functions/GeneratorCannotReturn

Rulesets

All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56

Exakat since

1.8.7

PHP Version

With PHP 7.0 and more recent

Severity

Major

Time To Fix

Quick (30 mins)

Precision

Very high

Features

generator

Available in

Entreprise Edition, Exakat Cloud