Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120103 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4436 invoked from network); 21 Apr 2023 14:18:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Apr 2023 14:18:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ADEAA1804C6 for ; Fri, 21 Apr 2023 07:18:09 -0700 (PDT) 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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 21 Apr 2023 07:18:08 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 76DEA5C00B3 for ; Fri, 21 Apr 2023 10:18:08 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Fri, 21 Apr 2023 10:18:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1682086688; x= 1682173088; bh=Ud3UB4F8ZX42wN3tD3fKDrfrD/7ciwZGd4sKQkdBhpY=; b=O HdgxFfTNr+Cj/fMbctlw2Uz5GkUW1C7kGOz92u7ggKxCZdVlieW2sr7kIGESC/xB Qn/SMgN+/tFrXYGYs2UHsHUuZmLnjzvTs7RVF/GK7EhSSO9fNSSW8tsipYg+1plQ XFX3J2hXpH7/ln1HZcpADGAqKu6eni0/KzWho0JQiN7K61Em56ZK6eRul9l/fz8C 3q7koG2oSDWZi99fFTQNKY4IZgv2V+AItbwX3xLDYp8zINkqFdGiReXxu8H5wauA v27JOKYcXiDsEKp5ua4HgFqJHdqp/TGY5adr7yb06xIYck5S9lo+WJC5HJJd/uB9 K+47L5U+wF9eCLhH1ps6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1682086688; x=1682173088; bh=Ud3UB4F8ZX42w N3tD3fKDrfrD/7ciwZGd4sKQkdBhpY=; b=isiHbc9sARoTZjky6XaLl14gM/vXB zCDbPkKIaeP4Av5YHkmzbAFfJ+Al7FSK7StnlKw847t5+kDlbFzwkIMHPWEVsZ8y d+69T5GJD6cNvYc7QJicTFuVYEdiYCR3ByFBApYmtTtAsM1UPW+PicgBYamJ7RXZ anvyV91X4k7shwerj0YoPW2hCxfswE9UiThjOyPAeMCxc+DN+YteWwxhhPPy7ba1 BUqp3qD/8BspthsUTrFBLX3ynnlENWYvPTjWZkeUflCEtqg7z5mFnm4/00VrjdYA 9kSDXg9LvwRwQddFRAdZUpWquas/VClb6M/2RYNjujVCwJyQLpy6bw+wA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedtgedgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 286D01700089; Fri, 21 Apr 2023 10:18:08 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-372-g43825cb665-fm-20230411.003-g43825cb6 Mime-Version: 1.0 Message-ID: <8fa3e835-41b8-4f57-aa9d-4fe0ac584766@app.fastmail.com> In-Reply-To: <6581c252-75c9-889d-75d2-eff5220216c2@gmail.com> References: <6581c252-75c9-889d-75d2-eff5220216c2@gmail.com> Date: Fri, 21 Apr 2023 14:17:30 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Expansion of PHP Symbols? From: larry@garfieldtech.com ("Larry Garfield") On Fri, Apr 21, 2023, at 9:02 AM, Rowan Tommins wrote: > Hi Marco! > > First of all, please do stick around, and keep learning and being > curious. Sometimes out of the box thinking does get somewhere. > > That said, a lot of what you've written here is actually what already > happens, and the problems are elsewhere. > > > On 21/04/2023 04:54, Deleu wrote: > >> 1- Use include/require >> 2- Custom Autoloading (not for functions but bear with me) >> 3- Use Composer/PSR-4 > > > The first thing to note is that these aren't *options*, they're *layers* > on top of each other: to load some code from a file, you use > include/require; to load some code *on demand*, you write an autoload > function, which uses include/require; to let *someone else* write that > function, you lay your files out according to PSR-4 and use Composer, > which writes the autoload function, which uses include/require. To piggyback on this point and go deeper into the "Composer/PSR-4" part: PSR-4 (and PSR-0 before it) are just standard rule for mapping a class name to a file. The intent is that an arbitrary autoloader written by anyone can then "find" classes from any package. PSR-0 came out in 2009. Composer came out in ~2012. It actually has four different loading mechanisms: PSR-0, PSR-4, "one big lookup map", and "files". PSR-0 and PSR-4 use those specs' class-name-to-file-name translation rules to look up a file on the fly. The "one big lookup map" scans the entire code base at dump time and builds up a big table of where every class-like is. Whether it conforms to PSR-4 or not is irrelevant. Then at runtime it just does an array lookup. I've many times run into the "fun" situation where a class was not properly named per PSR-4, but because the autoloader was set to auto-dump always, it never caused an issue as the built-map still worked! (Until it didn't, of course, because the lookup table is a cache that can get out of sync and give you no helpful error messages about it. I've lost much time this way.) And the "files" approach just greedily includes those files as soon as Composer initializes, and lets PHP take it from there. It's not even using an "autoloader" at all. (Fun fact: In Drupal 7, in the pre-PSR days, we built our own autoloader that worked on a "register and scan" model and stored a lookup table in the database. It... was not the best code I've ever written, but it did work for many years, and it's still running in the millions of Drupal 7 sites that still exist. For Drupal 8 we, thankfully, switched to Composer as the autoloader.) I've long felt that the advent of universal opcache usage and preloading (although few people use the latter, sadly) means that leveraging "files" should be a lot more popular than it is. That's what I do for my functional code (in Crell/fp); I just "files" include everything (which is admittedly not much) and move on with life. PHP is a lot faster at this than it once was. It's also why I'm only kind of luke warm on function autoloading. I'm not against it, but I don't see it as the blocker to more functional code that it once was. And as noted, how the heck do you then organize your functions so they're autoloadable? One per file is silly. So now we need to build some kind of map, and... we're back to the "one big lookkup map" approach, or something. I think there's still a lot of cultural aversion to front-loading code from the days when it was a lot more costly. PSR-4 is very good for what it is, but it's not the final word on code organization. It doesn't have to be treated that way, and that's a change that requires no core code changes. If we actually got working shared typedefs in the language, TBH I'd probably recommend people put all of their package's defs in a single file, "file" load it with Composer, and move on. Don't even bring PSR-4 into the picture. --Larry Garfield