Blob Blame History Raw
From d87b0685b5ec4e5df6d732414653f343bc44af8c Mon Sep 17 00:00:00 2001
From: Nikita Popov <nikita.ppv@gmail.com>
Date: Fri, 15 May 2020 11:03:05 +0200
Subject: [PATCH] Fixed bug #79600

Missed unsetting of DO_INIT in one case.
---
 NEWS                                |  4 ++++
 Zend/tests/generators/bug79600.phpt | 24 ++++++++++++++++++++++++
 Zend/zend_generators.c              |  1 +
 3 files changed, 29 insertions(+)
 create mode 100644 Zend/tests/generators/bug79600.phpt

diff --git a/Zend/tests/generators/bug79600.phpt b/Zend/tests/generators/bug79600.phpt
new file mode 100644
index 000000000000..4abe9784b694
--- /dev/null
+++ b/Zend/tests/generators/bug79600.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #79600: Regression in 7.4.6 when yielding an array based generator
+--FILE--
+<?php
+
+function createArrayGenerator() {
+    yield from [
+        1,
+        2,
+    ];
+}
+
+function createGeneratorFromArrayGenerator() {
+    yield from createArrayGenerator();
+}
+
+foreach (createGeneratorFromArrayGenerator() as $value) {
+    echo $value, "\n";
+}
+
+?>
+--EXPECT--
+1
+2
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 9d8546f5185b..4cd9087303a3 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -792,6 +792,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
 
 	if (UNEXPECTED(!Z_ISUNDEF(generator->values))) {
 		if (EXPECTED(zend_generator_get_next_delegated_value(generator) == SUCCESS)) {
+			orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT;
 			return;
 		}
 		/* If there are no more deletegated values, resume the generator