Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108538 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28004 invoked from network); 13 Feb 2020 15:03:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Feb 2020 15:03:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B57B11804AC for ; Thu, 13 Feb 2020 05:17:40 -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_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-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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, 13 Feb 2020 05:17:40 -0800 (PST) Received: by mail-io1-f54.google.com with SMTP id d15so6416877iog.3 for ; Thu, 13 Feb 2020 05:17:40 -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; bh=ngVOorpiKVVkd9U7xW0BeWS/eHQ4vSrGXThO6VYli+E=; b=nJeU8C11fDOr5e3STE/WnjPzilSfXRPPJvw6QifhUWTJeRl0hWfZiH+QRujY7Qvxy2 UcNpElGVrkq1OeTDH1FTjNebXA0rlaYKEOrm2EUAAWm1hEj/wWDDkJCm3/dsEwuz+3a+ 4Oi8LNvs0MT4Veu2SeafItV/wdi6T1EHDTHDshc77HX7lmJNhIoWLcS03zmd8Z3EvRwT n1IWvtqblJ55gG9mQMy44bh2aBjh7y+UIwpHWIswqh2fkQWo88KUvHiwtYsyGmidc5Gw LcXpAc/0mF/Za8bED6jCzTUXN4Sls5MX2GqsjF8h7kRLnO4qw65UhMGqtANM+BWzlaBK zCJA== 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; bh=ngVOorpiKVVkd9U7xW0BeWS/eHQ4vSrGXThO6VYli+E=; b=MzTGrrEhtDUqq59noQhdOW9K1HHUIAvy9rgSBy6FE2kmZ3sm3TmfabY2rSHFgAOlzs yepvTf7biazmdLOpOllQGbV276VfMQSvSsUFASUfIf/VBOw1wXa30M8DYWzB2MXZ+Dsc mqCL0HzIXboXhfZXDg4E8U5Ys3awXt+rhrvDiTF9lqMI5dAvsNNVEs6Agd66oJdAadO6 mjaScxYjZhEFVUccLqMtCWAWbCLYu7ljp6nNfbH9rG0w07m2FTJkrsMYGzYOv/smDQGi HUXKM/yFeU9mvGnxxoEF64qxTXbVvJjgcrr3ohSDrA5uuar2Zp+4Zf4JQlqYmgvclMu/ l7mA== X-Gm-Message-State: APjAAAUdvgdziRLZ8JH5lUyCRTDTCv/YWFV4RmlysCS6OlhZ/2hyQCgQ LFMjx+onbKoYdjeXaitHC7aHRALfofdLiW8akTmKsW/c X-Google-Smtp-Source: APXvYqw1z+n4C0oqs1gz1ZmyqW4XgwIU/WXagaYogA3ubmjbo9ieu7BJwDIedZviWLiGBXQXAQGgX/sB3MmVHpzOpFc= X-Received: by 2002:a05:6638:723:: with SMTP id j3mr23655653jad.131.1581599859340; Thu, 13 Feb 2020 05:17:39 -0800 (PST) MIME-Version: 1.0 References: <9829e5c9-9e32-9686-8ff2-ec7930dda709@gmail.com> <20d9da97-243a-a171-0412-7298b79e4dde@gmail.com> In-Reply-To: Date: Thu, 13 Feb 2020 13:17:27 +0000 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000caf904059e74e9bf" Subject: Re: [PHP-DEV] [RFC] From: rowan.collins@gmail.com (Rowan Tommins) --000000000000caf904059e74e9bf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 13 Feb 2020 at 12:04, Manuel Canga wrote: > > > On Thu, 13 Feb 2020 at 08:58, Rowan Tommins > wrote: > >> On 12 February 2020 23:12:34 GMT+00:00, Manuel Canga < >> manuelcanga@gmail.com> wrote: >> >El mi=C3=A9., 12 feb. 2020 23:01, Rowan Tommins >> >escribi=C3=B3: >> >In your example, you has the same options: >> > >> >> >> >1. Change import >> >2. Add namespace: >> > >> >['Acme\Global\I18N',\translate::function] >> >> >> There is no collision between 'Foo::translate()' and 'translate()', so >> there is no reason to change the import. That's true of executing the >> functions, so it should remain be true of resolving them to strings. >> >> There is collision with import which you added. > There is no collision. This is perfectly valid PHP code: namespace Foo; use \explode; class Bomb { public static function explode() { return 'Bang! Bang!'; } } $bangs =3D explode(' ', Bomb::explode()); There is no ambiguity here, explode(...) refers precisely to the global function 'explode' which is unrelated to the class method 'Bomb::explode'. The same applies if I import the function from somewhere other than the global namespace: namespace Foo; use Acme\BetterArrayFunctions\explode; class Bomb { public static function explode() { return 'Bang! Bang!'; } } $bangs =3D explode(' ', Bomb::explode()); Again, there is no ambiguity, explode(...) refers precisely to the function 'Acme\BetterArrayFunctions\explode, which is unrelated to the class method 'Bomb::explode. "explode::function" should mean "if I run explode() here, what is the fully-qualified name of the function that would run?" If there's no ambiguity of which function would run, there's no ambiguity of what value ::function should return. > * Here, 'my_function' is only a string. Maybe a global function( without > namespace ) or maybe a method or other case. With native array_map is a > global function. However, you can have a function like this: > > function array_map( $method, $array) { > \Collection::$method( $array ); > } > > In both cases, you could do: > > array_map(\my_function::function, [] ); > In the second case, it would be incorrect to use \my_function::function, because you do not want the answer to the question "if I run \my_function() here, what is the fully-qualified name of the function that would run?" Annotating the argument that way wouldn't be useful for tools, either - e.g. an IDE like PHPStorm would see ::function and offer "jump to definition", but in this case it would jump to the definition of the global function my_function, which is actually irrelevant. > > >> Importantly, it might not work at all, if ::function gives an error if >> the function doesn't exist. >> >> > ::function only would retrieve string, like as ::class, exists or not. In > fach, that code might not work at all due to class. What matter if Class > does't exist ?. ::class doesn't produce error. Look: > http://sandbox.onlinephpfunctions.com/code/0a8466a00974bc1ffc12b219569ced= 55753327bd > As pointed out elsewhere, an implementation of ::function would need to be smarter than ::class, because unqualified function calls look first in the current namespace, then fall back to global scope. For example: namespace Foo; function explode() {} echo implode::function; // Should return 'implode', because that is what implode() would run echo explode::function; // Should return 'Foo\explode', because that is what explode() would run Regards, --=20 Rowan Tommins [IMSoP] --000000000000caf904059e74e9bf--