Skip to content

Commit

Permalink
Fixed bug #78689
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Oct 29, 2019
1 parent 2bdb13a commit f9895b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions Zend/tests/bug78689.phpt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f9895b4

Please sign in to comment.