Fix Closure::call() on internal method closure

In this case we should use the original internal handler. Otherwise
the trampoline will attempt to free the closure, but the function
being used is not actually part of a closure anymore.
This commit is contained in:
Nikita Popov 2021-08-27 11:58:13 +02:00
parent 526407ca35
commit eda9f5f740
2 changed files with 13 additions and 0 deletions

View File

@ -0,0 +1,10 @@
--TEST--
Closure::call() on internal method
--FILE--
<?php
var_dump(Closure::fromCallable([new DateTime(), 'getTimestamp'])->call(new DateTime('@123')));
?>
--EXPECT--
int(123)

View File

@ -152,6 +152,9 @@ ZEND_METHOD(Closure, call)
my_function.common.fn_flags &= ~ZEND_ACC_CLOSURE;
/* use scope of passed object */
my_function.common.scope = Z_OBJCE_P(newthis);
if (closure->func.type == ZEND_INTERNAL_FUNCTION) {
my_function.internal_function.handler = closure->orig_internal_handler;
}
fci_cache.function_handler = &my_function;
/* Runtime cache relies on bound scope to be immutable, hence we need a separate rt cache in case scope changed */