Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115166 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94169 invoked from network); 27 Jun 2021 14:19:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Jun 2021 14:19:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4A2651804F3 for ; Sun, 27 Jun 2021 07:39:14 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 27 Jun 2021 07:39:13 -0700 (PDT) Received: by mail-qk1-f173.google.com with SMTP id bj15so24668009qkb.11 for ; Sun, 27 Jun 2021 07:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ralphschindler-com.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=N3B1sxSv/j7CtGlqihA8AElFCuR+9GrFDTYOJBK5c5E=; b=VfoeCRK6GFCjUN7upKsbXKsyqpW1ceW3b2g0dz3fvxKAZhpisACJz8x8Iq21l9Pj9/ Iloa89SGtNIwi+R+HK/FGhwfvw8voHs/qV4QLHQc9dWwXWtLFlFSUh+vLhZwr+AEBC/c sjoBf9UHHNvpKRdKiNjw9bFkaak6TCRlhZtbFn7kbjplfI+ur4+0JY8pLjl9/1qcZVgP hAODyeA4ck3iqaO0peZ/VJpQThon9BFpDXV9GFUz/DkYWzx3dOyGxcmhKfFbKspTYeQ9 eFx6kTqpuXDnuQo1PCZCOK8NeRrX/w+3XkPpfMGQKTNj4Py0fXtOZqzqYnTmbSVlNrG8 uw0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=N3B1sxSv/j7CtGlqihA8AElFCuR+9GrFDTYOJBK5c5E=; b=QA+ldHVmk8Lvy8FVxcHS7onrWoymp4qS0AdeHKfd1Dq9AjeMjJXRXnK+LrLr0yDM2h xlrPfHU1yfdZZnZIUu7NYo1atu9tuljFe1zaKKHehqh/voOj5MIInWxjIPRaEjkIIcHI 4jI47R0HznWsJ0C4++5hwZl3f8TX+zUX/ouZfE4BlcNCCJwg1nJRk31BTyME0HwWGoaz +s2DLY6qC5JXJXNFR+Jh7i5RJfSzJxVpuM/112KO7LrU3msQHVoDpzDOkLt0cRb3XkrE P1OmiXtsdgsqCloPu1VUeCbFk+gF8bBX+AKKN5p1ui7+dGuSgh0GFiERzF5A6Jg6Nudz z6gQ== X-Gm-Message-State: AOAM530VW7HACFiEhG8uuoLSyq4X/XgulZZKfbGwjitsEZGKAPL+3NY2 t0DB5uK1C6v7PZbp3FEwbYItbnzlsiwXptci X-Google-Smtp-Source: ABdhPJxBk4qgUVLqyhszJkzzHQGoUdynKcUyml9En58VK9YoIT9pBwhHm2EG13Ne6+4KvlkNtqeU+A== X-Received: by 2002:a05:620a:4085:: with SMTP id f5mr20949523qko.446.1624804752302; Sun, 27 Jun 2021 07:39:12 -0700 (PDT) Received: from Ralphs-ZiffBook-Pro.local (fl-67-233-173-166.dhcp.embarqhsd.net. [67.233.173.166]) by smtp.gmail.com with ESMTPSA id t11sm6682183qta.8.2021.06.27.07.39.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Jun 2021 07:39:11 -0700 (PDT) To: PHP internals Message-ID: <1ae611cb-b077-3db0-3237-c7ffa1c6e745@ralphschindler.com> Date: Sun, 27 Jun 2021 10:39:10 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: [Proposal] call_user_func_map(): flexible named parameter mapping for call_user_func* From: ralph@ralphschindler.com (Ralph Schindler) The short proposal: Make a variation of this work (notice parameter order and 'b' is goes unused): call_user_func_map( fn ($c, $a) => var_dump($a, $c), [ 'a' => 'the a value', 'b' => 'the b value', 'c' => 'the c value' ] ); // string(11) "the a value" // string(11) "the c value" The long proposal: Callables, Closures, Anon Funcs, etc - have enjoyed increasing popularity year over year. We've even gotten a shorter syntax for them `fn ()` and more RFC's are sure to be on their way. This proposes a method for a publisher/framework/producer (the caller of the callback) to document all the parameters that are available as named parameters, and subscribers/consumers (creator of the callback) could subscribe to what they need by name. For example: // documented callback parameters, this is what is available: $params = [ 'a' => 'value for a', 'b' => 'value for b', 'c' => 'value for c' ]; // a consumer only interested in $a and $c could write: $f = fn ($c, $a) => var_dump($a, $c); The consumer would then register their callback with the producer/framework/etc or pass as the parameter to whatever is consuming it $callbackSystem->register('some_event', $f) // or $doSomething->with($f); The framework could then call with success: call_user_func_map($usersCallable, $allAvailableNamedParameters); Currently the only way to do this is through array_diffing parameters found via Reflection, then passing them along to call_user_func_array() as a named array. Attempting to use call_user_func_array() without specifying all provided variables results in: Uncaught Error: Unknown named parameter X in ... Thoughts?