php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72373 TypeError after Generator function w/declared return type finishes
Submitted: 2016-06-10 04:47 UTC Modified: 2016-06-10 14:00 UTC
From: michael dot moussa at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.1.0alpha1 OS: linux (CentOS 7)
Private report: No CVE-ID: None
 [2016-06-10 04:47 UTC] michael dot moussa at gmail dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-10 13:58 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=792e89385ca6fc722a03590722eb7745a2374720
Log: Fixed bug #72373
 [2016-06-10 13:58 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2016-06-10 14:00 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2016-06-10 14:00 UTC] nikic@php.net
Thanks for the testing and reporting!
 [2016-06-10 14:01 UTC] michael dot moussa at gmail dot com
Thanks for the quick fix!
 [2016-06-22 05:58 UTC] krakjoe@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=792e89385ca6fc722a03590722eb7745a2374720
Log: Fixed bug #72373
 [2016-07-20 11:30 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=792e89385ca6fc722a03590722eb7745a2374720
Log: Fixed bug #72373
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC