Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108484 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46583 invoked from network); 11 Feb 2020 16:37:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2020 16:37:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 81FB41804DA for ; Tue, 11 Feb 2020 06:51:28 -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=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (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 06:51:28 -0800 (PST) Received: by mail-vs1-f42.google.com with SMTP id 7so6421003vsr.10 for ; Tue, 11 Feb 2020 06:51:27 -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=9UQEBZFvQWPfvR/k0mPbKmI+c4UAYZABIHEX0oJIgoU=; b=MfHK/WlMiEmbFTlt334L+B9Qf1I8Xh5t3Hzh4wzNuG3sgpbKzWe4O+uM7rtoaepWUS /zfVNQrL/CRhljVrWBO79EsWr2pTozA/qb/PI1Ikd9rez475Wa/LFUoXqpUoLgQ3Hy9v hc2uYi+Nvc54CvUcXtx+CmTVrUokLhxUmk/Hv+e+h6b5gMiVVdQZ6RTQlabbcAaCxGkA ruxbKucTB/H3IHQedS+gxMikGPiv4OrH8tk/w1DLelgCGt7yOJmuw7Wle2lvAsv87rYN qBhyJRda7BXbXEilaoYYnhB1hlESQGlBjn2S8ziVq+BfOg3bpg/OHRT6fzwBfaGgYdG3 cdhg== 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=9UQEBZFvQWPfvR/k0mPbKmI+c4UAYZABIHEX0oJIgoU=; b=RI9zEtTahENb65t9lx3j2xx0P+Z0Kh19kQWgU/C80929aWXbkZrMyOs2I4mHfYWoHy ICqCvZBaE0BZw6SFH1YW3vi6mNJRxtsHqiXOV1/QwcuhdR+jf4SEqFaVCKpJPVI4ekvD mhSu9L9S5W5LdPJpfex8eNRn/y8JpjxcVuwPg7soeMdP4gorsHEpcS9HfupWCT6ksFWX mbyybfZ+gG21UR4hBZqR2gK9jWe5qge1ykVmbJ//GmDQOiu4bBvc35lzuvx4KjRyqfZb Y/+Iy9DesSLj8VDNFeMPogdtwHJrlrL18GjbBjMJykbg8yG2VqK3G38tyhZP6P/++6lX nE+Q== X-Gm-Message-State: APjAAAUN5N8QoO2vkqT1aPXt1/ltDDYp5/wapz/EaN9HuCh/QU6He472 aPWMZ/rn8IFGTRPQYB+TigwXO0bh3ZesVTzw04w= X-Google-Smtp-Source: APXvYqysCAW/A8Pe9+FBoexl0Axw6IsOj1giHYwHGIZBwdkPR7EuVyMtLZntAjJqPWjfFfoI6He3qaMUBLxkttLQRgE= X-Received: by 2002:a67:f155:: with SMTP id t21mr9859892vsm.80.1581432687265; Tue, 11 Feb 2020 06:51:27 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 11 Feb 2020 09:51:15 -0500 Message-ID: To: Nikita Popov Cc: Manuel Canga , Nicolas Grekas , Diogo Galvao , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000008f8d3a059e4dfd41" Subject: Re: [PHP-DEV] [RFC] From: chasepeeler@gmail.com (Chase Peeler) --0000000000008f8d3a059e4dfd41 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 11, 2020 at 8:19 AM Nikita Popov wrote: > On Tue, Feb 11, 2020 at 1:43 PM Manuel Canga > wrote: > > > On Tue, 11 Feb 2020 at 13:16, Nicolas Grekas > > wrote: > > > > > > > > > > > > Le mar. 11 f=C3=A9vr. 2020 =C3=A0 12:52, Diogo Galvao a > =C3=A9crit > > : > > >> > > >> On Tue, Feb 11, 2020 at 8:14 AM Manuel Canga > > wrote: > > >> > > > >> > Hi internals, > > >> > I Would like to present a possible new "::func resolution" for you= r > > >> > consideration. > > >> ... > > >> > use function \My\I18N\i18n_translate; > > >> > > > >> > $mapped_array =3D array_map(i18n_translate::func, $array); > > >> ... > > >> > What is your opinion ? Do you see it useful ? > > >> > > >> I've wished for this on many occasions and think it'd be really > useful, > > as long > > >> as it could work with methods as well: > > >> > > >> $mapped_array =3D array_map(I18N::translate::function, $array); > > >> > > >> For what it's worth I guess it could just return [I18N::class, > > 'translate']. > > > > > > > > > I wish this would return a Closure instead, making $foo::function the > > equivalent of Closure::fromCallable($foo). > > > > Hi, Nicolas, > > > > Currently, when ::class is used, class with > > can or cannot exists in that moment. > > Using ::func( or ::function ), I think > > should keep the same behavior. > > > > Using ::func as alias of "Closure::fromCallable" check if function > > exists in that moment. It is certainly useful, but, I think it's more > > important be consistent > > > > Checking whether the function exists is really unavoidable for functions, > because you don't know whether > > namespace Foo; > var_dump(strlen::function); > > refers to 'Foo\strlen' or 'strlen', without first trying to look up the > former. > > I agree with Nicolas that this kind of feature would provide the most val= ue > if it created a Closure. This would circumvent all the issues outlined in > https://wiki.php.net/rfc/consistent_callables. > > Regards, > Nikita > 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. 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. 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= : class foo { const func =3D "bar"; } function foo(){} echo foo::func; Probably not something that happens very often, but, I think the 4 extra characters to prevent it would be worth it. --=20 Chase Peeler chasepeeler@gmail.com --0000000000008f8d3a059e4dfd41--