Bug #72373 [Opn->Csd]: TypeError after Generator function w/declared return type finishes
Edit report at https://bugs.php.net/bug.php?id=72373&edit=1
ID: 72373
Updated by: nikic@php.net
Reported by: michael dot moussa at gmail dot com
Summary: TypeError after Generator function w/declared return
type finishes
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: linux (CentOS 7)
PHP Version: 7.1.0alpha1
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=792e89385ca6fc722a03590722eb7745a2374720
Log: Fixed bug #72373
Previous Comments:
------------------------------------------------------------------------
[2016-06-10 04:47:17] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72373&edit=1
Thread (4 messages)