Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108503 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56235 invoked from network); 12 Feb 2020 05:44:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Feb 2020 05:44:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EFC5018053B for ; Tue, 11 Feb 2020 19:58:50 -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-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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 ; Tue, 11 Feb 2020 19:58:50 -0800 (PST) Received: by mail-yb1-f171.google.com with SMTP id j11so406314ybt.8 for ; Tue, 11 Feb 2020 19:58:50 -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=/EJ1sHTZR8SjFJ1Ymc6OXHCizQoCM3Zt4gu75bbM7p0=; b=maNXXLyh9UDMh1j+vecUqPsfkU6j3Zbe+YyUpTSqPTZHrENM0H7/JqVPZ7DaL5O9IJ V5htCwQCi1kmTmsXlVLUwzqVcnx0nfAyEYySy1g9RHYaWPbbvwUgIVx7Evt1vzcnwg5q 0sURZnFv13gK4Eq/O7vHX2QHmEgDPBXqa3SPQGJ66fbGqmG3P6LFe+u/MCrcVoWRy8cC O5HcGm0iGZhUdruf+693UwBaFyTO3EWKS5voo9qTzZpbnbe/6i/dulPjZ7Cg1Uaj0GPe +PRVIFlaYOaocaUeVhO12At55rlInv76xmW3qxK/ZJpJ8Yf1SxNNFGdCCQV8RRT/uGV6 6WPQ== 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=/EJ1sHTZR8SjFJ1Ymc6OXHCizQoCM3Zt4gu75bbM7p0=; b=O0JVS0XE8t2h9vGzNYJgvkVqMUAJx+7tLYHFgjMLyElDtMRcPDnJu0I0/tvvMWza4S zqVHciABGvBmtcx+srUUBO3vR0hR7YJHv9S5ZcM0f26ftnpwQZe93lTtiTC/Uf9x0VHJ 152vznSObyR2V4JXxOAqLVbzcLyUQZf9B/t0RzHBaw7L8aNlGlTvAiQPkU3kUklekEBY 7d0586CtuCS0f0ekIx7nLqaDdNNMCvD4RW4KrSDUPy2oqVxqUz/R/WdkILhDNct9umjL hkg69QA6bc19N3Ctdqsx/qIv7UqZESrlNo3GVmFHJA24RY2aLFjs0b9Q9ajwHKB6ZmFa zPPw== X-Gm-Message-State: APjAAAXJLCPtTElDOzfO9YfnHZmnli80Ytc9BGYhSkCkSiEfZbCGsaoQ rsem7V3VMOID8gEuIwlGpYuCBQ== X-Google-Smtp-Source: APXvYqzhh6UdQeFEXLOYeoxLa8oLYlOlpqJkTjZxtSBKRkylFw6NtaRy9EjMhgpszKuBmNwpFzcCwA== X-Received: by 2002:a81:25d3:: with SMTP id l202mr8779506ywl.506.1581479929931; Tue, 11 Feb 2020 19:58:49 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:6580:673d:95e8:48ed? ([2601:c0:c680:5cc0:6580:673d:95e8:48ed]) by smtp.gmail.com with ESMTPSA id w200sm2836953ywa.34.2020.02.11.19.58.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Feb 2020 19:58:49 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Tue, 11 Feb 2020 22:58:48 -0500 Cc: PHP Internals List Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Chase Peeler X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] From: mike@newclarity.net (Mike Schinkel) > On Feb 11, 2020, at 9:51 AM, Chase Peeler = wrote: >=20 > Can anyone thing 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. >=20 > If not, then I think it makes sense to return a callable. It might not = be > entirely consistent with the behavior of ::class, but, a class isn't > entirely consistent with a method/function either, so I think there is = some > latitude for small differences. >=20 > As for the ::func vs ::function. I think ::function is safer, since = it's a > reserved word. Otherwise you might run into issues with something like = this: >=20 > class foo { > const func =3D "bar"; > } >=20 > function foo(){} >=20 > echo foo::func; >=20 > Probably not something that happens very often, but, I think the 4 = extra > characters to prevent it would be worth it.------- Returning a _closure_ instead of a string would be providing a feature = we _already_ have instead of one we do _not_ have. If we had ::function returning a string we could use = Closure::fromCallable() to get a closure. Or today just use fn() =3D> = myfunc().=20 But if ::function instead returned a closure then there still would be = no way to extract the name of a function as a string from a symbol where = PHP can throw a warning if it does not recognize the symbol, such as in = the case of a typo. Seems to me having a shorter syntax to get a closure is an orthogonal = concern.=20 If we want a shorthand for closure we should create an additional syntax = for it but still provide a way to extract a function's name as a string = from its symbol since that is currently _not_ possible. Getting a = closure from a function symbol currently _is_ possible. Much better to provide ::function to return the name of the function = and ::closure get a closure that can call the function. =20 Or have ::function to return the name of the function and provide a = syntax something like ${myfunc} to return a closure, which has been = suggested later in this thread.=20 Or best would be to add ::nameof for functions, method, classes, = interfaces and traits and provide access to closures using either = ::closure or a new short syntax. -Mike P.S. A language I specialized in during the late 80's and early 90's = called Clipper implemented closures with the following syntax: - Without parameters: {|| expr } equivalent to function(){ return expr; = } and fn() =3D> expr; - With parameters: {|a,b| expr } equivalent to function(a,b){ return = expr; } and fn(a,b) =3D> expr; If we want a shorter syntax for function closures than fn() =3D> = myfunc() maybe we consider {|| myfunc() } which would be more general = purpose than only returning a closure for a function?