Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114542 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60566 invoked from network); 20 May 2021 17:36:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 May 2021 17:36:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 07CFA1804C8 for ; Thu, 20 May 2021 10:46:45 -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-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (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, 20 May 2021 10:46:44 -0700 (PDT) Received: by mail-ua1-f53.google.com with SMTP id 105so5801727uak.8 for ; Thu, 20 May 2021 10:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=hQ11LGTCx3VCX4LfMl+puuZD8cb6fjlz7lTISbscmlA=; b=phPFPYJS0i8fdUKGudSd/k2qOjuPjxZuiuhnknmkhqmpKZNqx4s6O/bDj0luYbrL55 iAo5EbdXXPSYyIyVXEB7Fsv/hwbyAHC7CRJvm8//XBlnxcoyhr9eeucvEBtakldehvIh VlBM+eVGaVStgzOZ46pNne3bwP26YrB5Fb8YVYQcSY9fB9YYdS3mwp4aGaMH68z7DgKH YZ07UgFNXrL2pmyaH2VblmbhPL3X7sYA473W7IrQP1Wb3mndmFTVx9K962+aoVnq+POg wYCq9pt/VGVGzyRnakvGKvk+QOMUbetwUIla6iAk987qBrP07xeAkoHf1eFa91yQ/PhP GdRg== 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:content-transfer-encoding; bh=hQ11LGTCx3VCX4LfMl+puuZD8cb6fjlz7lTISbscmlA=; b=LDlT3WCN5bg0BNW4MWnDrQwhEyAlum1dJ9drayvNEQcTq+10q1/n6gB/g2WhkmusE6 VKCdAptTrTr6WKDKRTY85pIWZwztdehvH4IBHlY8Fom3Ll5Y5nyYZ4m+AgKRl1XNuw/3 S52bJ1kqvnrcZGggQ9LQlRDgBrh3EOk+3b/tGvc6wDiLJyY1ioRiaITpSvOSDpF6BZ86 FnG7WrYen2Zg8iunOkAaFldVfqct7I4wp7JVkZSUZZJfe3TFPNwC6YkbWfKgANoLgXbW Lmy8YsvHSEh992CoxCJ58b3kPyUKWEqzAvSxr1tBWm6OhtOaNSmEnHQg+GNMofUTO+lh BK6Q== X-Gm-Message-State: AOAM530fKmqMRDTJeiPqhAquhgEbwrFO3n87f6F608YEmpTUaiSj9uB3 O8Cc+ExrObsDCSlmOyrInA6QatULRHO7E24EDfbaSg== X-Google-Smtp-Source: ABdhPJzkw/L2EwbgSU4T5UPrDkoXF0xAKGusDuOXtZ7vJxcxATy7VaPYLyybKmhs0fpAGiA7fGXk5bmQHK4CZYOK/J0= X-Received: by 2002:ab0:356f:: with SMTP id e15mr5689256uaa.52.1621532801361; Thu, 20 May 2021 10:46:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 20 May 2021 18:46:30 +0100 Message-ID: To: Guilliam Xavier Cc: Nikita Popov , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] First-class callable syntax From: Danack@basereality.com (Dan Ackroyd) Ond=C5=99ej Mirtes wrote: > Hi, I=E2=80=99m confused by the syntax, when I read it,... That is true of almost any new syntax. Some of us are still getting used to seeing \ in front of function calls. It doesn't mean that the syntax choice is a bad one, just that it's something new. For me, the main questions I ask myself is: * could I explain what the syntax means to a junior developer? * would the junior developer be able to remember it? For both of those questions, the suggested syntax seems fine. Guilliam Xavier wrote: > I wouldn't want to start new bikeshedding here; is there a > place that would be more appropriate to gather the possibilities Unfortunately I don't think we do have a better place. Being able to fork conversations so that "not completely off-topic, but not really that productive and getting in the way of the main discussion stuff", can be out of the way, but findable, is a feature that would be really useful for discussions. Nikita Popov wrote: > I am generally open to using a different syntax, Well, you might regret saying that. It might not be appropriate*, but having $() as marking a closure/callable seems 'clean' to me. Though obviously novel and likely to cause gut reactions: $(strlen); $($foo, bar); $(Foo, quux); $($foo->fn); $($foo); $($fn); Each would be equivalent to: Closure::fromCallable('strlen'); Closure::fromCallable([$foo, 'bar']); Closure::fromCallable([Foo::class, 'quux']); // aka Closure::fromCallable('Foo::quux'); Closure::fromCallable($foo->fn); Closure::fromCallable($foo); Closure::fromCallable($fn); For the code: class Foo { public $fn; public function __construct($fn) { $this->fn =3D $fn; } public function bar() { } public static function quux() { } public function __invoke() { } } $fn =3D function() { echo "I am function\n"; }; $foo =3D new Foo($fn); cheers Dan Ack * at least in the sense that it's a big syntax change, for a relatively small feature.