Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107975 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43866 invoked from network); 3 Jan 2020 16:53:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2020 16:53:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 636FC1804F3 for ; Fri, 3 Jan 2020 06:57:30 -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-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (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:57:29 -0800 (PST) Received: by mail-io1-f47.google.com with SMTP id b10so41537961iof.11 for ; Fri, 03 Jan 2020 06:57:29 -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=mLhFNJweQ4SqQEBdkPgSuvjCpqIiiQKjhJehs9djIRI=; b=HjIQhKXCU0tnYgmwh27g3Euxxt33wAT07/UkOTY97WYX4U/ItkNrsSTaoC8tltYTZG P5AN9atVUdqV95hGv1IvDj4xXk4yL+ckr7zZ/TqqBDuerfEQ7uU7H8YPw+szie/5jtum pErFGF0QGSNltplvvJWXKChZl8dWjKuTeiB2ecEejBZgzzHBIQXd5NkbYAf6yzF+aAdd gfecqIvDj4LNUWHcBATqqa4XsrYn2pCL398o66xJXJXRdq76fGUVG1XvvmZvxLZc/HPv F2ilh2rlI3S6rbKf9COoujh95vyW6cL10rUhOvMs7PQuDfa9mDUBVZprnDVaAa5T+H5Q efoA== 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=mLhFNJweQ4SqQEBdkPgSuvjCpqIiiQKjhJehs9djIRI=; b=V9DE8xYE0aWsy46pnF+64mMvsMrt5CnOA+38EBOHkaabVZe1IlBbduTlhU2TDONvJ+ g/vyt07aDIvZsNkVovuv97qTcnTnZKdtJwpmdPO4yB1ABgU7ucv7aWAjlOAEOcOREiY8 srFWYBQCZ+XXWijMda3d/W9dhp7CaEOOnwoIrRqlrmtRGVBYf5FibXwejZiDrZg9Pkym TvRSccNd2bnQVCVKRWuR7aacDTrFycwCMtQ65IFCuiqWM0muX8XyAKHtTQZENyQZ0aA+ erykhm3m4OeL+TtH2wl0kK93YpzU5ErtNnEV5vwRHuVFONb7pZEXx9ZZURsVnufH9qfJ 9IWA== X-Gm-Message-State: APjAAAUzwx7Pf+WBFeDPaJNC7i/6EAfiVYDnSBybZHnTmaVZ2qZ1ZUh7 D4bzYG5TXk3qRRe9oEc7dWuNXt/R1jxfAeyY+5dsDw== X-Google-Smtp-Source: APXvYqyoN/PpReM5GwnllE1wc+NQmIpbXSAidl7LRTfyIUte6PYemrwFpyn+Ch50dDBLRqAw/0KEFvuobaJtZ2uEnzw= X-Received: by 2002:a02:cc75:: with SMTP id j21mr67974170jaq.113.1578063448192; Fri, 03 Jan 2020 06:57:28 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 3 Jan 2020 14:57:16 +0000 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000433ab9059b3d87b3" Subject: Re: [PHP-DEV] Autoloading functions/consts without a performance impact From: rowan.collins@gmail.com (Rowan Tommins) --000000000000433ab9059b3d87b3 Content-Type: text/plain; charset="UTF-8" On Fri, 3 Jan 2020 at 14:39, tyson andre wrote: > > 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? > > The example you were thinking of would call \strlen on line 2, \Foo\strlen > on line 3, and \Foo\strlen on line 4. > (because the caching is per-opcode, not per-file or per-namespace) > Sorry, I should have been clearer - I wasn't asking for a literal answer based on any particular implementation, I was asking rhetorically what a user would expect to happen. Let's make the example a tiny bit more complex: namespace Foo; function one() { echo strlen('hello'); } function two() { echo Foo\strlen('hello again'); } Now the behaviour of my program can completely change depending on which of those functions I call first, which might even depend on user input. Regardless of exactly how the cache works, that kind of unpredictability is a recipe for disaster. The only way to make it predictable again is to pre-define the namespaced function in my startup code, at which point I don't need function autoloading. Regards, -- Rowan Tommins [IMSoP] --000000000000433ab9059b3d87b3--