com php-src: Fixed bug #78689: NEWS Zend/tests/bug78689.phpt Zend/zend_closures.c
| From: | Nikita Popov | Date: | Tue, 29 Oct 2019 14:06:16 +0000 |
| Subject: | com php-src: Fixed bug #78689: NEWS Zend/tests/bug78689.phpt Zend/zend_closures.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-109121@lists.php.net to get a copy of this message | ||
Commit: f9895b4bf5c6cdef0106f763cd95d95e98f039ae
Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 29 Oct 2019 15:05:59 +0100
Parents: 2bdb13a1f776fccf89506d63eb71e950df96c21e
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f9895b4bf5c6cdef0106f763cd95d95e98f039ae
Log:
Fixed bug #78689
Bugs:
https://bugs.php.net/78689
Changed paths:
M NEWS
A Zend/tests/bug78689.phpt
M Zend/zend_closures.c
Diff:
diff --git a/NEWS b/NEWS
index 6fba02d9c88..b56409b4afa 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP NEWS
Lundin)
. Fixed bug #78752 (Segfault if GC triggered while generator stack frame is
being destroyed). (Nikita)
+ . Fixed bug #78689 (Closure::fromCallable() doesn't handle
+ [Closure, '__invoke']). (Nikita)
- COM:
. Fixed bug #78694 (Appending to a variant array causes segfault). (cmb)
diff --git a/Zend/tests/bug78689.phpt b/Zend/tests/bug78689.phpt
new file mode 100644
index 00000000000..2273fd35320
--- /dev/null
+++ b/Zend/tests/bug78689.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Bug #78689: Closure::fromCallable() doesn't handle [Closure, '__invoke']
+--FILE--
+<?php
+$a = [function () { echo "123\n"; }, '__invoke'];
+$a();
+
+$b = Closure::fromCallable($a);
+$b();
+?>
+--EXPECT--
+123
+123
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index 23ea9bc2e25..3efb7ea1166 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -268,8 +268,15 @@ static int zend_create_closure_from_callable(zval *return_value, zval
*callable,
mptr = fcc.function_handler;
if (mptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
- memset(&call, 0, sizeof(zend_internal_function));
+ /* For Closure::fromCallable([$closure, "__invoke"]) return $closure. */
+ if (fcc.object && fcc.object->ce == zend_ce_closure
+ && zend_string_equals_literal(mptr->common.function_name, "__invoke")) {
+ ZVAL_OBJ(return_value, fcc.object);
+ zend_free_trampoline(mptr);
+ return SUCCESS;
+ }
+ memset(&call, 0, sizeof(zend_internal_function));
call.type = ZEND_INTERNAL_FUNCTION;
call.handler = zend_closure_call_magic;
call.function_name = mptr->common.function_name;