Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108547 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74168 invoked from network); 13 Feb 2020 20:04:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Feb 2020 20:04:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 69B9A1804D1 for ; Thu, 13 Feb 2020 10:19:13 -0800 (PST) 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.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 ; Thu, 13 Feb 2020 10:19:12 -0800 (PST) Received: by mail-yb1-f176.google.com with SMTP id k69so3423444ybk.4 for ; Thu, 13 Feb 2020 10:19:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ugc4AOoqhMx8GDzpR0LatomYWV2pieicEKHyISVl+Oc=; b=AhkGQ7DziukqnYQtCPQXxv2S0xWgGHunvq4FgF/K1mh6DrTfqqjTHxCmYQlxQc0GEH dTJw2FAispC/I8IjGcnyFs/xUBj1XrDufLVvpatvF0bP8CoabUtw0Fw92tBDM+BrjWr1 RbuXET9bvnEY35xax0TBbrRLBGx09U6YgRt7hdbGfvnBCqXeDMdrOiET19buuYNwjez5 LPSGgSArlfQnaZH/tcS+XOJxEOVlJgvZuUo8AUMwuNl5ypCdVoYBz6WlqgOHc2fp4gq0 5qbzAyLFAGp2I7e87H7+z5XNMUma+Lfv5NUYqarUHjEUX87IHyahVK7F37aTR2XhEMFa GKdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ugc4AOoqhMx8GDzpR0LatomYWV2pieicEKHyISVl+Oc=; b=DvAAMljIfECt347dzy/kG5+DInvlV/ZClgQB4datC8GsLHc33Zyx4cPX4Cn8VyXhO2 Sf6YvbZQl0jqtzaxC9ZFJuyLSVwIxiDrEUeLLVtY0MH41MB003RetZDvGQrFfWwwbqrV SYDAo43Ac6M+53iOaNNXPSKoR1+En/HCkpRD83kMQ8MQYFRuFZ3qT+m9Y4OKoBmdGuwc C9cRO0DNLtGNMxn0rWAchKPY/csUt/VvsGtxKXENMOFSNt9EWGxcLCyTjyOlYSxIvxYI RLHJ95ATTt2nD7gPiYMsM8xviy2Yzq3bwoc6dX6fBq/urPJoJwG5YfcOaYe+VSvvahOq 6XBA== X-Gm-Message-State: APjAAAXPeIfK5cJRb7XKjYfGBCCigi3awdHnYm/ul+vAq5VkrYbvhoGr f7NS1gd0qo7eOJ8nmDQ03j5+Ag== X-Google-Smtp-Source: APXvYqxyaVLutTNc6DSVLA4eZ3TTaoVIIVs2FF6wwsAnJALJa28cYWImotvXLyh1SIfytKaQLpTQ6Q== X-Received: by 2002:a25:9c01:: with SMTP id c1mr15777353ybo.200.1581617949953; Thu, 13 Feb 2020 10:19:09 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:c40d:6267:8a93:b5b9? ([2601:c0:c680:5cc0:c40d:6267:8a93:b5b9]) by smtp.gmail.com with ESMTPSA id p62sm1438708ywc.44.2020.02.13.10.19.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Feb 2020 10:19:08 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Thu, 13 Feb 2020 13:19:08 -0500 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <2C404984-AD76-4CDF-8E1A-04DF8EF024DD@newclarity.net> References: <10FCCCED-B8AE-4394-91B3-0FEB448E2398@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] From: mike@newclarity.net (Mike Schinkel) > On Feb 13, 2020, at 12:26 PM, Rowan Tommins = wrote: > Right, I'm with you now. However, I think the answer people are = suggesting > to "how do we get the name string?" is "why do we need to?" 1. Say I want to provide users with the ability to build queries and use = functions where I want to provide the names of the functions to the = users: $qt =3D QueryTool(); $qt->addFunction(substr::function); $qt->addFunction(add_product::function); $qt->showUI(); 2. Say I want to serialize any configuration that uses functions. You = can't serialize closures but you can serialize function names to a = database or JSON. 3. You cannot use a closure as an array index so if you want to use the = function name as an array key to associate additional information to the = use with the function, such as: $qt =3D QueryTool(); $qt->addFunction(substr::function, array(=20 new FuncParam( 'string', 'string' ), new FuncParam( 'int', 'start', QueryTool::Optional ), new FuncParam( 'int', 'length', QueryTool::Optional ) )); $qt->addFunction(add_product::function, array(=20 new FuncParam( 'string', 'product_id' ), new FuncParam( 'float', 'price' ) )); 4. Being able to compose quality error and warning message that include = function names. > Or as Chase Peeler more eloquently put it: >=20 >> Can anyone think of a use-case where you would want a string name of = a >> function and a callable would not be acceptable, besides possibly = debugging >> code that said 'echo "I'm calling ".myfunction::function;'? = Everything that >> I can think of that accepts a function name, also accepts a callable = (e.g. >> array_map), but I could be forgetting something. Eloquently maybe, but of limited vision. > There's a Venn diagram, essentially, of: > a) use cases where a Closure would be useful, but a string wouldn't > b) use cases where a string would be useful, but a Closure wouldn't > c) use cases where either a string or a Closure would be useful >=20 > If (and it's a genuine open question) all the use cases fall into > categories (a) and (c), we can make the syntax for closures simpler by > skipping the "get name" step and making foo::fn return a closure = straight > away. >=20 > So the question is, are there use cases that fall into category (b)? Yes. Definitely. But since I seem to be in the minority of caring about the name, let me = propose the following which was influenced by Larry Garfield's most = recent post. Since it seems that people want the convenience of a short = notation to get a closure, how about this: function foo{} foo::function =E2=80=94 Returns name of function foo::fn =E2=80=94 Returns closure for function=20 Since using `fn` creates anonymous function closures it kinda makes = sense that `::fn` would return a closure. -Mike