Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108549 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80147 invoked from network); 13 Feb 2020 20:34:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Feb 2020 20:34:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 090CF1804F8 for ; Thu, 13 Feb 2020 10:48:47 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE,SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 13 Feb 2020 10:48:46 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 378DAF9B for ; Thu, 13 Feb 2020 13:48:45 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Thu, 13 Feb 2020 13:48:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=mr1Q/JSebrXUCdrnx+DlrvUx3Qb5z/Y0QYhYYDHvM GQ=; b=JSmE8doyGEGLZRnxh1+3Gk5a6/2nCX540FQlA6U4441zD7iL79znj9RtJ 4tQUKLrXUlJjAuorygaaE9kJsA2ioj8nWDunEwf0/FFSPSBv0sds+RuHITU818E+ TdsqpyMFKVQ54SQ9Q5VgDqWKulN3kG9nS2UHSo+KlwSSyvGs68U/IO6klm5sg6+d pr/xV/ZWuzD9GdFLDaP7PWCXg44e2JewA1hm1zhuBXIDc1FNhj/51IQP65FldzJV OAmRsK/TlpTFNCT4C4e2mGJIYmee3E+YnrUfuK/Q15Sr/VDCqZmx9TurJgkW9RcX fMWWUjqqgfgWOr8LNDp9OUVsUinnw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrieekgdduudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep lhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 42BBF14200A2; Thu, 13 Feb 2020 13:48:44 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-802-g7a41c81-fmstable-20200203v1 Mime-Version: 1.0 Message-ID: In-Reply-To: <2C404984-AD76-4CDF-8E1A-04DF8EF024DD@newclarity.net> References: <10FCCCED-B8AE-4394-91B3-0FEB448E2398@gmail.com> <2C404984-AD76-4CDF-8E1A-04DF8EF024DD@newclarity.net> Date: Thu, 13 Feb 2020 12:48:23 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] From: larry@garfieldtech.com ("Larry Garfield") On Thu, Feb 13, 2020, at 12:19 PM, Mike Schinkel wrote: > > On Feb 13, 2020, at 12:26 PM, Rowan Tommins wrote: > > Right, I'm with you now. However, I think the answer people are sugg= esting > > to "how do we get the name string?" is "why do we need to?" >=20 > 1. Say I want to provide users with the ability to build queries and=20= > use functions where I want to provide the names of the functions to th= e=20 > users: >=20 > $qt =3D QueryTool(); > $qt->addFunction(substr::function); > $qt->addFunction(add_product::function); > $qt->showUI(); >=20 > 2. Say I want to serialize any configuration that uses functions. You= =20 > can't serialize closures but you can serialize function names to a=20 > database or JSON. >=20 > 3. You cannot use a closure as an array index so if you want to use th= e=20 > function name as an array key to associate additional information to=20= > the use with the function, such as: >=20 > $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' ) > )); Those are valid examples. I suppose along similar lines would be toolin= g that uses a builder to generate compiled code. (Eg, if $qt were used = to then generate an optimized function in a class on disk.) Flipside: In those cases we really should standardize static methods bet= ter than with arrays, yet none of these address (nor can they) instance = methods. > 4. Being able to compose quality error and warning message that includ= e=20 > function names. >=20 > > Or as Chase Peeler more eloquently put it: > >=20 > >> Can anyone think of a use-case where you would want a string name o= f a > >> function and a callable would not be acceptable, besides possibly d= ebugging > >> code that said 'echo "I'm calling ".myfunction::function;'? Everyth= ing that > >> I can think of that accepts a function name, also accepts a callabl= e (e.g. > >> array_map), but I could be forgetting something. >=20 > Eloquently maybe, but of limited vision. >=20 >=20 > > 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 str= aight > > away. > >=20 > > So the question is, are there use cases that fall into category (b)?= >=20 > Yes. Definitely. I agree, the above examples demonstrate valid use cases for (b). > But since I seem to be in the minority of caring about the name, let m= e=20 > propose the following which was influenced by Larry Garfield's most=20= > recent post. Since it seems that people want the convenience of a=20 > short notation to get a closure, how about this: >=20 > function foo{} >=20 > foo::function =E2=80=94 Returns name of function > foo::fn =E2=80=94 Returns closure for function=20 >=20 > Since using `fn` creates anonymous function closures it kinda makes=20= > sense that `::fn` would return a closure. >=20 > -Mike thinking-face-emoji.gif. I could be convinced of that. It seems like "= both" is a possible solution, but my concern would be someone using one = of them in a case where either works, inadvertently, when the callee is = expecting just one. Eg, getting into the habit of using foo::fn, and th= en using it on a builder routine that chokes "later" when it tries to se= rialize something. --Larry Garfield