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

From: Date: Fri, 10 Jun 2016 14:00:32 +0000
Subject: Bug #72373 [Csd]: TypeError after Generator function w/declared return type finishes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201529@lists.php.net to get a copy of this message
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: Closed Type: Bug Package: Scripting Engine problem Operating System: linux (CentOS 7) PHP Version: 7.1.0alpha1 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: Thanks for the testing and reporting! Previous Comments: ------------------------------------------------------------------------ [2016-06-10 13:58:21] 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 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

« previous php.bugs (#201529) next »