Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108495 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90024 invoked from network); 11 Feb 2020 20:48:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2020 20:48:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0E734180569 for ; Tue, 11 Feb 2020 11:02:14 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,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-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 11:02:13 -0800 (PST) Received: by mail-ot1-f44.google.com with SMTP id j20so11233590otq.3 for ; Tue, 11 Feb 2020 11:02:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ys6w7V82xUKR/74jHoDT2PMv8anAGmJ21GiU5b2Muck=; b=YmsFtFypLojjxE5BJeeyUWERfCR1zTvOVO7N/mOpaRTumq9HralvuO/RxaY6gPjjap kh3BWzdN9bVNqnhIOHnmAqZD8fYxQmbq36pNzKYAeO60iF/qiCk+EHCKHDIBYvkIAhx6 EILeWAfLUgyL3Oz5p49ei7j7hPo4nOPj1H3dPFfDos0H6QcR9Ha2LdY4g6jeVz2dsN9O e5drsJ6STOGKbu1jiYdbxFUHcQM1/RkNjJRcX83jCwfUafAfSRjNjHScs0Bryw+Iwqts Qp2x7qixDFGDW12HpLdlj0EPHvaMERfj/nbrj6uZoI5hh4L8c02vpjhaeftDRT0NVEm9 p/Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ys6w7V82xUKR/74jHoDT2PMv8anAGmJ21GiU5b2Muck=; b=a/7MvbZ9gHlz8hdscv8LNLlzmvNv82EBEtv/rzSpmlrYftqrg6Ql5B41Xp8JGlSfPX vhn40XsQwaZK44K/qdZ5xpcpdc4e3+0rTpCul0XZulhp8+vUazUaSfhHI7s9VMSehuPZ hSlUXScv4Gl267w7KH31BFEKHd13Ye6d45Q1F9W/EBD97cok9NmFd/yPp6ODOQ0GXfPl J3nEjiIQX2Y6uqXZghuErA6h6eRmvHjrtp9HSPRbPH4DyfL6mDTjAwBE19isfVTZZhB8 YMl6A+UbTq3kvm6SKWt9f7HETd6RX0pC95+GcmgBJOzXydbk4+VCrcv/H513lt7JJIar 7Hrg== X-Gm-Message-State: APjAAAWvC166qzmLsR10m5Fj2MS3qBL+mXWU5tyh6P5ffumKWjx3Ezqy iUMvw+nrmV7v/gSFv2bT3hMhQJFa488Iq4yJ8Zw= X-Google-Smtp-Source: APXvYqzp+TK9g1xAsXpgiSeNMapzFa4UDVghH1AGhscDewWVJbAVxJXLlep2bfIb1Ome0f5sVQnUqjcux3MA/erQOws= X-Received: by 2002:a9d:ecc:: with SMTP id 70mr6134116otj.182.1581447729448; Tue, 11 Feb 2020 11:02:09 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 11 Feb 2020 20:01:57 +0100 Message-ID: To: Manuel Canga Cc: Dan Ackroyd , Nicolas Grekas , Diogo Galvao , PHP Internals List , Nikita Popov Content-Type: multipart/alternative; boundary="000000000000250b57059e517e43" Subject: Re: [PHP-DEV] [RFC] From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --000000000000250b57059e517e43 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable wt., 11 lut 2020, 18:42 u=C5=BCytkownik Manuel Canga napisa=C5=82: > On Tue, 11 Feb 2020 at 17:49, Dan Ackroyd wrote: > > > > Nicolas Grekas wrote: > > > I wish this would return a Closure instead, making $foo::function the > > > equivalent of Closure::fromCallable($foo). > > > > I didn't include the following in that RFC, because I thought it would > > be too controversial, but I think it's worth considering a new syntax > > for this. > > > > Given the code: > > > > function foo(); > > class Zoq { > > public function Fot() {} > > public static function Pik() {} > > } > > $obj =3D new Zoq(); > > > > > > Then these: > > > > $(foo); > > $($obj, Fot); > > $(Zoq, Fot); > > > > Would be equivalent to: > > > > Closure::fromCallable('foo'); > > Closure::fromCallable([$obj, 'Fot']); > > Closure::fromCallable('Zoq::Fot'); or Closure::fromCallable(['Zoq', > 'Fot']); > > > > Or similar. > > > > The justification for having a dedicated syntax is that I think > > readability is quite important in code, and it's reasonably common for > > me to have quite long lists of 'callables'. > > > > [Bar::class, foo1::function], > > [Bar::class, foo2::function], > > [Bar::class, foo3::function], > > [Bar::class, foo4::function] > > > > vs > > > > $(Bar, foo1), > > $(Bar, foo2), > > $(Bar, foo3), > > $(Bar, foo4) > > > > The latter is far easier to read for me. > > > > Nikita Popov wrote: > > > This would circumvent all the issues outlined in > > > https://wiki.php.net/rfc/consistent_callables. > > > > Probably there would still be some issues with some of the weird stuff > > happening internally in SPL related code where the deep horrors > > rest...but we can leave them alone...and they might not wake. > > > > cheers > > Dan > > Ack > > Other option: > > Closure::fromCallable('foo'); > Closure::fromCallable([$obj, 'Fot']); > Closure::fromCallable('Zoq::Fot'); or Closure::fromCallable(['Zoq', > 'Fot']); > > to > > > <$foo, Fot> > > > > E.g: > > array_map(, $array); > array_map(, $array); > > Do you like ? > That reminds me an old draft RFC https://wiki.php.net/rfc/short-closures where I thought curly braces can be used to create closure from syntax nearly the same as invoking but without parentheses. That way we can provide clear intent - I mean if whatever is around: curly braces or $ with parentheses IMHO it should be consistent with call like format. For example: $(strlen) or {strlen} for Closure::fromCallable('foo') $($foo->Fot) or {$foo->Fot} for Closure::fromCallable([$obj, 'Fot']) $(Zoq::Fot) or {Zoq::Fot} for Closure::fromCallable('Zoq::Fot') Etc. The same inside like a call but wrapped in something and with no parentheses part. Cheers, -- Micha=C5=82 Brzuchalski > --000000000000250b57059e517e43--