Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108002 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52822 invoked from network); 6 Jan 2020 11:02:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2020 11:02:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 03DFB1804D1 for ; Mon, 6 Jan 2020 01:07:26 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE 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-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (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 ; Mon, 6 Jan 2020 01:07:25 -0800 (PST) Received: by mail-il1-f170.google.com with SMTP id p8so41980744iln.12 for ; Mon, 06 Jan 2020 01:07:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FUrQY0JriiDXRVrVOnBF50yv6EgVvhT6008KSdi7NHY=; b=1gqDERZXrFBV5bxaKSnjybquPB1OXhtVvOMQjsxTpCv4la0w1OOrfK8AJPkKs760vy gqh/GXwOT8sOCl2rKPvRd8PNIg1qTYoHS01M9CeBXGTxURn6mIFGxplz1fcJ3QDHqoG9 cy8GEMFtvh1MvzYcCLXDZaOREMQ5OGoZfBlmMeHdg5UYV6REMdkgxWCYOGQcaGoUMhDf M/uIBeSkFxTTWf5CLUbu8xcjXddbU4KFZr2ID7YIsZfU+PFAp/1MpvNAb6JDoPKxcYG3 cG8vmX0Ec/W1fzIrEMN3I4dTeFoUU4VNAjK9QHWXXZqOS4lxZwxI8ylysxi7NgbqDpv/ 9eig== 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:cc; bh=FUrQY0JriiDXRVrVOnBF50yv6EgVvhT6008KSdi7NHY=; b=rNH0tIBn0eCzHO5qDps+I3lnXLkr3eYrW6t2q7PFEri/QukSx1sL/2KzP70ZemplnK kcccPEwxvT7Qoe72kAyKVv3rn18gsz9CCqqKnvZu7/DdHDbji7ERK3D+udOTizxBwhmQ mg/8rQKMBrcVcsONtdHSVFnB66hAjU7c02ZOyzw/j9o881MtGlAvIGX5Lv9xuJ+TM260 BTw/RKHkZgKMzc8MPc6Z5/9fJ6ZjxdPWMYOODYSjP6t2MjjWYhG+96PaGe3Jxwsx/cvT KmfHeW7TTe8fXmQ4FcMt0yv+a4+ZCZzxAa2LxAFmSxnAns16tKw/KGAp6rh9Hd2o/Lt9 S+Ig== X-Gm-Message-State: APjAAAXIgyhqV0zjsRTvU7AbCZo+2z+4IovLHh76di6ttIpffOnfQweB tvve0TZN9ZoGOj6BxIQxepwE5yX0u4UHPmuLRLbluQ== X-Google-Smtp-Source: APXvYqzCEW+vwGJJYLCcEy6qxZPmkuW9/vgMZcER16hotYm8/Ii7LikLnmb8eQ4d3Wy6OqK3UfcjTLBxpRCDjOzOLj8= X-Received: by 2002:a92:91d8:: with SMTP id e85mr86129791ill.146.1578301642570; Mon, 06 Jan 2020 01:07:22 -0800 (PST) MIME-Version: 1.0 References: <97a60300-6041-5ce0-e509-91657235650a@gmail.com> In-Reply-To: <97a60300-6041-5ce0-e509-91657235650a@gmail.com> Date: Mon, 6 Jan 2020 10:07:15 +0100 Message-ID: To: Rowan Tommins Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000c209a0059b74fc32" Subject: Re: [PHP-DEV] Autoloading functions/consts without a performance impact From: rasmus@mindplay.dk (Rasmus Schultz) --000000000000c209a0059b74fc32 Content-Type: text/plain; charset="UTF-8" On Sun, Jan 5, 2020 at 7:48 PM Rowan Tommins wrote: > On 05/01/2020 18:03, tyson andre wrote: > >> Yes, I'm saying that the autoloader should be called for each lookup, so > >> autoloading of Foo\strlen should come between checking if Foo\strlen is > >> defined, and checking if \strlen is defined. > > That would be the intuitive approach for a language, > > but as mentioned earlier, > > it would significantly harm performance of existing code for php 7 > > (slightly without an autoloader, more with autoloaders), > > and I can't imagine that getting approved. > > > Yes, I'm fully aware of the downsides. I just think relaxing that > constraint would lead to a horribly confusing language. > > > > I'd considered that option, but that introduces its own surprises, > > which I'd consider to have more frequent and significant impact on > applications that start using this. > > > > namespace NS; > > function f1($x) { > > return mb_strlen($x) + 1; > > } > > function f2($x) { > > return \mb_strlen($x) * 2; > > } > > > > Calling f2() then f1() would work, but f1() then f2() would not work, > because f1() wouldn't autoload. > > > True; again, it violates the user's expectation, which I think can be > summed up this way: > > - The autoloader for a function should run the first time that function > would run if it was pre-defined. > > That in turn stems from an even more fundamental expectation: > > - An application using an autoloader should behave the same as one which > defines all functions in advance. > > > The more I think about it, the more I think we should just be optimising > for the case where everything *is* defined in advance. As far as I know, > PHP's autoloading is an anomaly among programming languages, and maybe > it has outlived its usefulness. > I would argue that name resolution, the way it works right now, is also somewhat of an anomaly among programming languages. Removing autoloading from the language would have two major implications: 1. You have to figure out what to load in advance - thinking you can just preload all *.php files in a folder is probably pretty naive, because some of those files (PHP being a scripting language) are going to be actual be scripts (CLI scripts, tests, etc.) and not just declarations. 2. Code generation - and I mean, think of that what you want, but PHP lends itself well to code generation, and many projects (ORMs, template engines, annotation parsers, AOP and other meta-programming frameworks, etc.) use the autoloader as a hook to generate code on the fly. So this seems like a fairly drastic change to the language, which might render a lot of projects defunct with no recourse. --000000000000c209a0059b74fc32--