Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108462 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93328 invoked from network); 11 Feb 2020 13:19:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2020 13:19:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9B26B180210 for ; Tue, 11 Feb 2020 03:33:38 -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,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-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 ; Tue, 11 Feb 2020 03:33:37 -0800 (PST) Received: by mail-wm1-f53.google.com with SMTP id t14so3089972wmi.5 for ; Tue, 11 Feb 2020 03:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inventis.be; s=google; h=date:from:subject:to:cc:message-id:in-reply-to:references :mime-version; bh=SM2rnkfc8yhHWIBevjODtDNmi/nuebq4wL5aVwoDwQc=; b=aR7b4kRUuJU44fD+Qcx08+UFQYWXZ+GRTvBEIV9lClUft8CKw9n/je6jUyEZzJTjbR kDYajhsNC1VMR5ZpMumfVxs/INoclk6TxQKDvSsgQDPYAer9s8zcq4q8K9BGUWkf9Cv1 vT/Nt0hpjh2UpE9lSiTrlmUM68z3/1+xpdddCkkFHzNtWLaYtlTV435gcstPPs1wFvPZ I5MgNGulWOSjZi6PlSiPomXEkcvpdKHkZecu9xmN10kNQMsYQfdj8hyTE22L2zs7K3JR EhKkiwU4x423nsm4qXtYauPLtKlzRFxfvmln9cV2QybwoYm33J4CXxkhvUFppwjm8/M4 G3fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:message-id:in-reply-to :references:mime-version; bh=SM2rnkfc8yhHWIBevjODtDNmi/nuebq4wL5aVwoDwQc=; b=Ik16ipOfcsISBGTe5UlZ4Mi5Yat7YU1zQdgebzghCFJ1YnFc1eHuzelVC3lZnWz+kj epwJ+Bw40rVrgeLywvCSwZb47+yAIOCBt3dnv+aVENYvBmQXk5AgjnonByXvc96oeq2e ezOzfA/jVrz7nnMq5F4W2/WxNsEaNifVAawSXiiogijDwd+I/yTyKLmSFb4WAiX4FO5O Cy791JtiXJ8DmzrqHpf91o3E5vvpAmDRJey+bKA1i+onAsmW1hsrNnH1DH7+JOyhuYhZ I03c2s1LYHuyOvVsnaNtPIsntn+vEY6YAgPO2kHK6Ki+jYhTpjQJb01AeUvVhE3NSM4z OPsw== X-Gm-Message-State: APjAAAUfY9POBV3VA1p0yOWWbBrZabql0IDYDTupM8mkdpcG9+9/j+KY YsgODCpQRV5jcDhMOtyvK9jr1w== X-Google-Smtp-Source: APXvYqy6XNtDnwuHULgD+8UJqutAPuHQNz5MFE9FjyXtl2q8TVYF/R86o+faiF9ne5pQVKMtHlmedA== X-Received: by 2002:a7b:cc82:: with SMTP id p2mr4986130wma.159.1581420815701; Tue, 11 Feb 2020 03:33:35 -0800 (PST) Received: from hephaestus ([2a02:1807:4410:101::23]) by smtp.gmail.com with ESMTPSA id i16sm3591151wmb.36.2020.02.11.03.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 03:33:35 -0800 (PST) Date: Tue, 11 Feb 2020 12:33:34 +0100 To: Manuel Canga Cc: internals@lists.php.net Message-ID: <1581420814.35391.0@inventis.be> In-Reply-To: References: X-Mailer: geary/3.34.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Subject: Re: [PHP-DEV] [RFC] From: tom@inventis.be (Tom Gerrits) Hi Manuel Thanks for bringing this idea forward. Adding a non-string construct to reference functions uniquely seems like a good idea and would be consistent with the existing ::class keyword for classes. I'm wondering if it would be useful to take a page out of the book of other programming languages in order to shorten the notation further: > // First file. > namespace A\B; > > function foo() { } > > // Second file. > use function A\B\foo; > > function bar(callable $c) { } > > > // Current approach. > bar('\A\B\foo'); > > // Notation without parantheses, references imported function. > // Similarly, in the future, Class::method could reference a > // class method. > bar(foo); > > // Notation with references, could be expanded in the future > // for static class methods, such as &Class::method. > bar(&foo); The second example can already be achieved by defining your own constant that references the fully qualified name and importing it. However, an explicit, separate, import of these constants is still needed, which is not ideal. A suffix "::func" would also be useful, but allowing shorter notation would improve readability when using the functional programming paradigm and composing functions. Op di, feb 11, 2020 at 12:13 schreef Manuel Canga : > Hi internals, > I Would like to present a possible new "::func resolution" for your > consideration. > > In first place, PHP now support "::class" in this way: > > use My\I18N; > > $mapped_array = array_map([I18N::class, 'translate'], $array); > It avoid add Full I18N namespace in callback. > > However with functions is different: > > use function \My\I18N\i18n_translate; > > $mapped_array = array_map('\My\I18N\i18n_translate', $array); > > What is the useful here of importing the function?. > My proposal is ":func" in order to avoid full namespace in callback of > functions. E.g: > > use function \My\I18N\i18n_translate; > > $mapped_array = array_map(i18n_translate::func, $array); > > "::func" should validate if a function with `` is > imported. > In this case, "::func" is replaced with FQN of this function, > otherwise with only "" > > What is your opinion ? Do you see it useful ? > > Thanks and I'm sorry for my English( I'm a Spanish ). > > Regards