Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108505 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81201 invoked from network); 12 Feb 2020 08:59:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Feb 2020 08:59:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7DE87180211 for ; Tue, 11 Feb 2020 23:13:07 -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, RCVD_IN_DNSWL_NONE,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-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 23:13:06 -0800 (PST) Received: by mail-lj1-f182.google.com with SMTP id q8so1022974ljj.11 for ; Tue, 11 Feb 2020 23:13:06 -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:content-transfer-encoding; bh=8qJcDfomazanQ/IJbITy5CdvzVTh7nmRM7mNi6cO1VM=; b=eJnwleWkQwM9kjcnXBnW4KQ82aCggr5CguCaDnSrUImniJEpTWNsmEluuZ9X41h7vx 0TabxX/j776IM8uHmSxc0C9No+GFh6IS06CaknY10Fh6MjW1sBUerlGGCOHBGvha2ML/ 0G2dOSZNT7uthHtqI8jmzkAZEF7TDmJm+Ux8mEqHAbspewEe9XEY5YBhK9+CdaSrNpHt QvYI8LSibLxYNU1nlGb+F0Ay703oqh2mnyrXbGS8JAm/sjJE+oSp/wheZsVhlXf6RbRP JLUqj2m59YYaQTOOaA7FD9lj49YciWq6NfZ0BQf/07kNOejMNxWJ108+18WIpJVAt0aZ IBeQ== 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=8qJcDfomazanQ/IJbITy5CdvzVTh7nmRM7mNi6cO1VM=; b=b2Gc8dxelHL8GgGh99S3xrz6LC+B5fn8v2OUxCkmzqIednacC9lqVynt7Rz4zMrAMS QaCu4w+2baum4q5smYGcdyhTGpZ8oa6zLdC3pnb776rOzHPecPHxvs21sEHuczwkjqDb 8aDrr0HwQ7AglIgNkFi0ojHbkcsgIuB3E/dftBhwrRJZhBI13SYly6Y1Y/iLPZ5G59qF TgmSCeCBi6iEvMCxi+fM3IkONklmaBr2WaDzcLvZetNJmEz3JlDPlw1r6gvI0STqpQVM +Tqdzha2e//X/Bv5RMCC0F/V5er/SL4t+SF3o2cZLXREaMGKxo//lO4M9Y4E4EVs8PmO 6AAQ== X-Gm-Message-State: APjAAAW4L9MTDBWz7YMjl2B6feB3POehzIhN1b3/IH4FdSWrA44fK646 cafYODc/zlNyjl+ZtVcnYuAkkr3ImyA/3NeCug== X-Google-Smtp-Source: APXvYqzwLybPPxcsKEEd68I1Ft0UOAwl9xAM1pjBo2T1AzCbRTO9AP9Uy8gdsYr7wLvAWbPMWxIaraZgu9hliYeZJRA= X-Received: by 2002:a2e:3e0d:: with SMTP id l13mr7034713lja.70.1581491583803; Tue, 11 Feb 2020 23:13:03 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 12 Feb 2020 08:12:53 +0100 Message-ID: To: Mike Schinkel Cc: Chase Peeler , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] From: guilliam.xavier@gmail.com (Guilliam Xavier) On Wed, Feb 12, 2020 at 4:58 AM Mike Schinkel wrote: > > Or best would be to add ::nameof for functions, method, classes, interfac= es and traits One problem is how would `x::nameof` resolve when you have several `x` symbols (of distinct kinds) in scope? ``` namespace Theirs { class Foo {} const BAR =3D 2; function qux() { return '3'; } } namespace Mine { use Theirs\Foo as x; use const Theirs\BAR as x; use function Theirs\qux as x; var_dump(new x); // object(Theirs\Foo)#1 var_dump(x); // int(2) var_dump(x()); // string(1) "3" // *** hypothetical: *** assert(x::class =3D=3D=3D 'Theirs\Foo'); assert(x::const =3D=3D=3D 'Theirs\BAR'); assert(x::function =3D=3D=3D 'Theirs\qux'); assert(x::nameof =3D=3D=3D ???); } ``` > 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::fromCallabl= e() to get a closure. Or today just use fn() =3D> myfunc(). > > 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 cas= e of a typo. > > Seems to me having a shorter syntax to get a closure is an orthogonal con= cern. > > 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 fro= m 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. > > Or have ::function to return the name of the function and provide a synt= ax something like ${myfunc} to return a closure, which has been suggested l= ater in this thread. That might deserve consideration indeed... --=20 Guilliam Xavier