Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68871 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14840 invoked from network); 2 Sep 2013 21:57:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2013 21:57:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.50 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.50 mail-vb0-f50.google.com Received: from [209.85.212.50] ([209.85.212.50:57727] helo=mail-vb0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/40-29856-5B905225 for ; Mon, 02 Sep 2013 17:57:10 -0400 Received: by mail-vb0-f50.google.com with SMTP id x14so3318480vbb.23 for ; Mon, 02 Sep 2013 14:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=eyrnFHN6UTQ8pQkZ5C1fZVizdIprehPlMNGEUv7C0kU=; b=WvqX5HjV1NeDuB0F+LkIaaAekpWac0VXnuULnBT0fZSEWkDpAxAOCX3B7Xb6W7j36d BCOap7ihKdPFKUyn2FM8+kHDmNOXvoxuDrhN+IGkjMjsW+Boo0/pRkzDxs/zjl8UTs+L 1J4d/0Uv8H6vzK72r2yAIKoykEyz+F+MrZsHrH2B0M2FgBautfWA19XNI+9hPG9N0ob9 CFWTjqq6j7Q7kpiY9EQPEbO9cm6/ZpF3Z/vP2qFOIvrhXEBOnXpdlhpiM4gYy0AHdA+C H/lOWUjFL5fd6LGbphH+/xyW36sZyA9/ZRDzfS/ch+wQWnyvlKuLzMyReRIF5T+cevG3 FucQ== MIME-Version: 1.0 X-Received: by 10.220.199.5 with SMTP id eq5mr24934147vcb.16.1378159025704; Mon, 02 Sep 2013 14:57:05 -0700 (PDT) Received: by 10.58.94.201 with HTTP; Mon, 2 Sep 2013 14:57:05 -0700 (PDT) In-Reply-To: <5224EEEF.3070204@sugarcrm.com> References: <5220437A.7050008@sugarcrm.com> <5220D212.3010101@sugarcrm.com> <61FCD6C4A31248078FEAD2BA73D7CD44@gmail.com> <7AF31CC1D1554454AC95AE758D23E92E@gmail.com> <52243F6C.7070806@sugarcrm.com> <5224EEEF.3070204@sugarcrm.com> Date: Mon, 2 Sep 2013 17:57:05 -0400 Message-ID: To: Stas Malyshev Cc: Nicolas Grekas , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b5db26a2bd4f404e56da7bc Subject: Re: [PHP-DEV] Re: Function autoloading From: ircmaxell@gmail.com (Anthony Ferrara) --047d7b5db26a2bd4f404e56da7bc Content-Type: text/plain; charset=ISO-8859-1 Stas, On Mon, Sep 2, 2013 at 4:02 PM, Stas Malyshev wrote: > Hi! > > > So the only case this effects is that you can't autoload a function from > > the same namespace that you're currently in without explicitly using > > that function. > > > > That's not such a huge issue. > > I think it is such a huge issue, because this means this functionality > can not be used for reliably loading namespaced functions without prior > declaration, and this is pretty much the use case we've been preached > about all along. So if it doesn't work in this case without prior > declarations just for it, than how it's better than require? It doesn't *need* prior declaration. It needs either prior declaration or qualification (absolute or relative). But more on that in a sec. > > But "fixing" that would be such a massive BC break... > > There's nothing to "fix", it was a conscious decision about how > namespaces must work. Alternative is doing \strlen each time you need > string length, which would be just silly. So what your saying, if I understand you correctly, is that PHP was intentionally designed to be non-deterministic? And it was designed that way to save a single character? To get why I think that's such a big deal, let's look at some sample code: namespace Foo { function test1($input) { return strlen($input); } function test2($input) { return strlen($input); } var_dump(test1("test")); // int(4) // Simulate require eval('namespace Foo { function strlen($input) { return 42; }}'); var_dump(test2("test")); // int(42) var_dump(test1("test")); // int(4) on 5.4+, int(42) on 5.3 } The eval is just there to simulate a require_once. Thanks to function caching, NOTHING makes sense!!! http://3v4l.org/MMvFv If you don't agree that behavior is wonky, then I'm not sure where else to go. > > You would only need to explicitly `use function` those in your current > > namespace. Any outside (relative or absolute calls) would still work > fine. > > It's not "only" - functions in current namespace are exactly those I'm > likely to use. Look at the code where you use classes. How many times to do use a class from your current namespace vs another one. The code I've looked at tends to favor other namespaces significantly... > > And after all, this is the exact reason we implemented `use function`. > > Because namespaces WERE useless for functions until last week. Now we > > have the power to be explicit with our calls. > > I don't think RFC proposed well before this issue was raised was > actually meant only to fix broken function autoloading proposal. I > sincerely hope it has more uses than that, otherwise it's a pretty big > mistake. > > That's how functions (and namespaces) have always worked. Give it a > > try: http://3v4l.org/S6FN8 Keep in mind, functions have been treated as > > No it's not how it worked - function resolution rules were always "try > namespace, then global", unless alias is explicitly specified by use > (aliased name is treated as fully qualified, because this is what the > function of aliasing is). Just try to remove "use" statement and see. It's only "try namespace, then global" in the case where there's no `\` in the function name. Compile code that does the check: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_compile.c#1938 > > The big difference is that last time there was no mechanism to be > > explicit with what you wanted your code to do without fully qualifying > > every call. Today we have `use function`. > > Which is the same specification, just at the beginning of the file. I'd > rather do one require then ten use functions. My opinion is producing > autoloader that is inconsistent with how language itself treats import > would only produce more WTFs and more people thinking nothing in PHP > makes sense and nobody cares about internal consistency of the language. > Anthony PS: I think it's ironic talking about internal consistency of a language in the same reply where you justify "try namespace, then global" as a good design feature. Just pointing that out... --047d7b5db26a2bd4f404e56da7bc--