Bug #78689 [Ana]: Closure::fromCallable() doesn't handle [Closure, '__invoke']

From: Date: Mon, 28 Oct 2019 11:31:22 +0000
Subject: Bug #78689 [Ana]: Closure::fromCallable() doesn't handle [Closure, '__invoke']
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223490@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78689&edit=1 ID: 78689 User updated by: nicolas dot grekas+php at gmail dot com Reported by: nicolas dot grekas+php at gmail dot com Summary: Closure::fromCallable() doesn't handle [Closure, '__invoke'] Status: Analyzed Type: Bug Package: Scripting Engine problem PHP Version: 7.3.10 Block user comment: N Private report: N New Comment: Note that we could take this as an opportunity to introduce a new type of callables: given [$closure, 'method'], this would be resolved as $closure()->method() when called. We use this style in Symfony where we need lazy-callables. Previous Comments: ------------------------------------------------------------------------ [2019-10-28 11:22:31] nikic@php.net It looks like there's a hardcoded assumption that any trampoline function passed to Closure::fromCallable() must be a __call/__callStatic trampoline, while here it's an __invoke() call-via-handler. ------------------------------------------------------------------------ [2019-10-28 11:13:25] nikic@php.net This actually gives me a segfault on 7.2: ==24448== Jump to the invalid address stated on the next line ==24448== at 0x600000001: ??? ==24448== by 0x9FE0E9: zend_call_function (zend_execute_API.c:820) ==24448== by 0xA52718: zend_closure_call_magic (zend_closures.c:252) ==24448== by 0xA538BB: zend_closure_internal_handler (zend_closures.c:632) ==24448== by 0xA7E0C8: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:911) ==24448== by 0xB03C47: execute_ex (zend_vm_execute.h:59781) ==24448== by 0xB09005: zend_execute (zend_vm_execute.h:63792) ==24448== by 0xA186A1: zend_execute_scripts (zend.c:1498) ==24448== by 0x97BDB3: php_execute_script (main.c:2599) ==24448== by 0xB0BCAD: do_cli (php_cli.c:1011) ==24448== by 0xB0CE6B: main (php_cli.c:1403) ==24448== Address 0x600000001 is not stack'd, malloc'd or (recently) free'd ------------------------------------------------------------------------ [2019-10-18 12:06:28] nicolas dot grekas+php at gmail dot com Description: ------------ php > $a = [function () { echo 123; }, '__invoke']; php > $a(); 123 php > $b = Closure::fromCallable($a); php > $b(); PHP Warning: Invalid callback , no array or string given in php shell code on line 1 PHP Stack trace: PHP 1. {main}() php shell code:0 PHP 2. Closure->__invoke() php shell code:1 php > The warning is wrong - Closure::fromCallable() could return $a actually :) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78689&edit=1

« previous php.bugs (#223490) next »