Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108485 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50284 invoked from network); 11 Feb 2020 16:59:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2020 16:59:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4EC2A180541 for ; Tue, 11 Feb 2020 07:13:49 -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, 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-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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 07:13:48 -0800 (PST) Received: by mail-lj1-f170.google.com with SMTP id x7so12021227ljc.1 for ; Tue, 11 Feb 2020 07:13:48 -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=5kdcltL8YBy1gY3cH8klN4XjvxBMoBUCmKP1Fqrz8IE=; b=ETcR2Gs2pG1XDRJcLyPVdcpgA2Y7xZMHvvX0cTyJlucZh2Ac+VTTO4kRumwZs49t+1 LoWxqlYxYR+RhLnJTmwiOrh5C9HL/ZMDitA8oDM7k1jR8rMs5Tr99fY4jX5KhLF8UB/U bDXL9Cr7JFUeT37K0F5GGuxNWZ/bdQ0T3k4RB/Ysz+p1lwwZ2ZLvWWK28FKEHrEoUivr WDrVROrWdU0+bW11ZyAnrTgy0K9osQ50/RztsnmUFIwS8cfEfHrEE37NYkMhHqNjFvmg 5eTOC/H71PnkzOyLE+P58Ck6YkQgremTxka9rsXZUmgBd9c5+c2KEL3C3ZhdQjkmdOrz YCkA== 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=5kdcltL8YBy1gY3cH8klN4XjvxBMoBUCmKP1Fqrz8IE=; b=oYOwJzNMxbdiQNeitp2lL35H49vynth5RNEllABOsAs7gAnerMDWlfgRfkdWWOaaA3 PD3N5mwjWD+QoeSXNSSXVU6IqV5Zs1l1ufo4V+8hOyQNq3Iv8Ikgys+hoBGoOifWmNFr eqgaoJWhRLMqFbgzNnyMkVlpxjAH8L0+pOcUnGbRGaPR/vktVT7WK5U6NG9r0sQriLjZ HhHu00QMXCfrIjDUqJay70f3E0xIA6MyClvSE0rlBiHx6/8ye9IZKuBn3ql4XuNGPiYU XeC8AImomD3JvGSmS9HrPN9L1CkQN77yeoruYrQ5G3IUjXKwQVlTJhQN37592KJ5KZLv wfpA== X-Gm-Message-State: APjAAAVxh8cno+Kl8fa+jYRevtbT+qv7isUXnfx/WOut+YNMXbJZ6y0J ZIWnwYa8c8NB7uATiAoKKavtxfEEqsukiatPY1E= X-Google-Smtp-Source: APXvYqwfaNtQpMTv/f9lwAJaGEp7RDx4UKpMYhhItMc3V4o5w6P4P2dQs2X3Rxj7SFJ0SHwIuvtRBjX+/9vkqab2HWI= X-Received: by 2002:a05:651c:102c:: with SMTP id w12mr4541394ljm.53.1581434026477; Tue, 11 Feb 2020 07:13:46 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 11 Feb 2020 16:13:34 +0100 Message-ID: To: Chase Peeler Cc: Nikita Popov , Nicolas Grekas , Diogo Galvao , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] From: manuelcanga@gmail.com (Manuel Canga) On Tue, 11 Feb 2020 at 15:51, Chase Peeler wrote: > > > > On Tue, Feb 11, 2020 at 8:19 AM Nikita Popov wrote= : >> >> On Tue, Feb 11, 2020 at 1:43 PM Manuel Canga wro= te: >> >> > 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 yo= ur >> > >> > 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 use= ful, >> > 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 th= e >> > 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 va= lue >> if it created a Closure. This would circumvent all the issues outlined i= n >> 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 fu= nction and a callable would not be acceptable, besides possibly debugging c= ode 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 entir= ely consistent with a method/function either, so I think there is some lati= tude 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 th= is: > > 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. > > -- > Chase Peeler > chasepeeler@gmail.com Hi, Chase, Yes, '::function' is better. I don't know because I thought 'func' was used with short functions. One case which string can be useful but a callable would not be acceptable = is: array_map([I18N::class, translate::function] ); Although it's true that can have side effects. Thanks, Chase,