Bug #72373 [NEW]: TypeError after Generator function w/declared return type finishes

From: Date: Fri, 10 Jun 2016 04:47:20 +0000
Subject: Bug #72373 [NEW]: TypeError after Generator function w/declared return type finishes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201502@lists.php.net to get a copy of this message
From:             michael dot moussa at gmail dot com
Operating system: linux (CentOS 7)
PHP version:      7.1.0alpha1
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:TypeError after Generator function w/declared return type finishes

Description:
------------
The provided Test Script produces the Expected Result in 7.0.7, but
encounters a TypeError in 7.1.0alpha1. The issue seems to have been
introduced by the removal of the ZEND_VERIFY_RETURN_TYPE case in this
commit:
https://github.com/php/php-src/commit/cb3825a8dc551e6a43b4ea3a01dbd0584bf606bb#diff-8f41738bb0ceb7bf7c9882a4b399ab6eL645.

Removing the Generator return type declaration or adding an empty return
statement after the final yield seems to function as a workaround, but
naturally I'd prefer to change nothing if this break was an
unintentional.

Test script:
---------------
<?php

function foo() : Generator
{
    yield 1;
    yield 2;
    yield 3;
}

foreach (foo() as $bar) {
    echo $bar . "\n";
}

Expected result:
----------------
1
2
3

Actual result:
--------------
1
2
3

Fatal error: Uncaught TypeError: Return value of foo() must be an
instance of Generator, none returned in /tmp/foo.php:8
Stack trace:
#0 /tmp/foo.php(10): foo()
#1 {main}
  thrown in /tmp/foo.php on line 8

-- 
Edit bug report at https://bugs.php.net/bug.php?id=72373&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72373&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72373&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72373&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72373&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72373&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72373&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72373&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72373&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72373&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72373&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72373&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72373&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72373&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72373&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72373&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72373&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72373&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72373&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72373&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72373&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#201502) next »