Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107972 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34514 invoked from network); 3 Jan 2020 16:14:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2020 16:14:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5F1A51804C2 for ; Fri, 3 Jan 2020 06:18:47 -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=-2.1 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 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-f42.google.com (mail-io1-f42.google.com [209.85.166.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 ; Fri, 3 Jan 2020 06:18:46 -0800 (PST) Received: by mail-io1-f42.google.com with SMTP id n11so34721618iom.9 for ; Fri, 03 Jan 2020 06:18:46 -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=q1ROl5/nDfC2RLRaOJAOyT21LBrLghLXuylaignm61Q=; b=b1IDIWX5G6zIt5BV0KSbhxqdXKJMdCLBraHnyF6PSn2TWpq/6NftaHbfEa/79jpXMh JsS7gulnTERUIwHl5kDKdrdiHeJ2Urnvcia0dyIECczka0cU+20ESGYyBqGTInjxx8Qt FoLapCzy6Wy/uFt/ntAI++XNBQEoYlONSq71lazkreoKkSPqwzvOMtXDeBCs71fStzJJ PCOYeg7/IDwlfc7m8gOoYNHFtz4nhUf5nQzWNraCxg+lcBZ+lk3/4UPt/OUP98JlOLHW JlciwlGlnAfgPK7N4w147h9mj2+w/Cssn6Lhx5Jt1tjfOOuu4Xu6LWqKoShbZml4Ps9f dy8Q== 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=q1ROl5/nDfC2RLRaOJAOyT21LBrLghLXuylaignm61Q=; b=Nb9RdybHyI95hlCfZwWsAcQBibtgjQwQ0ZknILInQGosC93+KwZsNtpw+GZJfaqZVN tWMjJg93Ef8sxkgy1/X27x2MIDPOFqWoVsPhW7coJs5Kqe/SdHKSTvChs+SVl/4aMAmG YD5CTT8jLMBf1yT5d6dtWXsQqAjRGtRtX5USmnvzYmPL3VjX4MXn8deh/fUPnk12S30+ K4o6nHIVpl93rDglvxb7xBZbpzkEkbsip0/D87RSJJ8Rp4aW/rjFKxXS8UFI5PHr0QjK 6jhwueTH67TOrNKzp6efb0leSbGkwYESzBQP4lyROFqunDIY4BNv2tHSlQshqhTwYdqU Cmhg== X-Gm-Message-State: APjAAAUEZpRb/BwqNh1mNMQCRsp6XbYrOByGMx++iB7Zca0mo2O8isGf P8TLFu0jDQr+qvRWCh/KEgULuI1M59g9BNtgo8QpFkMu X-Google-Smtp-Source: APXvYqxvR/+dBluJieM0wArrlBjSl8JmQ4C4al5P5rBPIyb15/gaSxPwX+1B4Sn+LNmd1Kw6ama4Nu+SO8zMCQWSxzk= X-Received: by 2002:a5e:9902:: with SMTP id t2mr56958163ioj.120.1578061123664; Fri, 03 Jan 2020 06:18:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 3 Jan 2020 14:18:32 +0000 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000b5beaf059b3cfca2" Subject: Re: [PHP-DEV] Autoloading functions/consts without a performance impact From: rowan.collins@gmail.com (Rowan Tommins) --000000000000b5beaf059b3cfca2 Content-Type: text/plain; charset="UTF-8" On Fri, 3 Jan 2020 at 01:51, tyson andre wrote: > 1. It (first) looks for a function from the current namespace: A\B\foo(). > 2. It (next) tries to find and call the global function foo(). > 3. (Optional) NEW ADDITION: Next, if both functions were undefined, > the autoloader(s) attempt to autoload the function A\B\foo() > (and call it instead of throwing if found) before proceeding to step > (4.) > 4. NEW ADDITION: If both functions were undefined, > the autoloader(s) attempt to autoload the global function foo() > (and call it instead of throwing if found) before throwing an Error > I think running the autoloaders out of sequence from the actual name lookup is a recipe for confusion. Consider this case: namespace Foo; echo strlen('hello'); // Finds a global function at step 2, so doesn't trigger the autoloader echo Foo\strlen('hello'); // Explicitly namespaced function, so triggers the autoloader echo strlen('hello'); // Should this run \strlen or Foo\strlen? If we cache the resolution to global function at line 2, removing that line changes the rest of the program. If we don't cache it there, then what happens if we run this code in a loop? Admittedly, that ambiguity can already be introduced if you explicitly define the function between the two calls, but that can be worked around by pre-loading all functions for a namespace. The whole purpose of autoloading is that you don't need to think about when definitions are loaded, so this kind of case would be much more likely to bite people. Regards, -- Rowan Tommins [IMSoP] --000000000000b5beaf059b3cfca2--