Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113569 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79157 invoked from network); 16 Mar 2021 17:49:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 17:49:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CE9391804C0 for ; Tue, 16 Mar 2021 10:43:36 -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=4.0 required=5.0 tests=BAYES_50, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 ; Tue, 16 Mar 2021 10:43:36 -0700 (PDT) Received: by mail-lf1-f43.google.com with SMTP id v2so50718117lft.9 for ; Tue, 16 Mar 2021 10:43:36 -0700 (PDT) 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=zXggKfTbVnytLerQVEnBk4Ad4mhS6NC7J0nbG1MwyXk=; b=Br7vP+N/Lwbv2s1rWbI4t/3c6NmZGKmEY95FyUtmkObt+rXuekwKs6pSp5ahRSFqUd EX0CiXnKN8m6YtYnQAazUqOAF/IjcXRjlw9VQWkzsBzDN0TpRP1XgPKxt4vippPDWeFw RvPgn2aBMJw/tDZoXyG4nOA8M2Fl/I8rsROtbPIFc4P4CxiH6ezr+1JLFFx0kqqFzLmD pXD9bE8wqLLqcjGJibixU2pZGIMDn5N/eBRaq1ejLLka9vUOTxWJf87bp8hr1HzZnFhJ rjgFw6Ba1P8WLNJMQrmO4KPDIdmgEROKL+z/j/nvYuXun8QBn3X4r/kX7yglwP1XAYBi vkEg== X-Gm-Message-State: AOAM5327EP5UxwhzSd0F1lsu/Ty1aEvWBoX0nI7iwpBMpZxBELOAmSSx ECg/u2bLB4YnpxdeGk2lzEdDHdYliQAGCB34YFHODHuXnSQXlg== X-Google-Smtp-Source: ABdhPJwyek9LqBiUIgDeLP/q4liTBNFBevbCk/h3LREUio54IsxBrvxs+NbWwb1rAle5FA0OJU4ac2YSS7pROFMDDI8= X-Received: by 2002:ac2:4d8e:: with SMTP id g14mr11943366lfe.572.1615916614661; Tue, 16 Mar 2021 10:43:34 -0700 (PDT) MIME-Version: 1.0 References: <604f9c58.1c69fb81.361e9.305fSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <604f9c58.1c69fb81.361e9.305fSMTPIN_ADDED_MISSING@mx.google.com> Date: Tue, 16 Mar 2021 12:43:23 -0500 Message-ID: To: Mark Randall Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000cdccb405bdaae76b" Subject: Re: [PHP-DEV] [RFC] Autoloader Classmap From: pollita@php.net (Sara Golemon) --000000000000cdccb405bdaae76b Content-Type: text/plain; charset="UTF-8" On Mon, Mar 15, 2021 at 12:41 PM Mark Randall wrote: > I would like to propose the addition of a new mechanism of autoloading > classes - a classmap that will be consulted prior to checking the > spl_autoload_register'd callbacks. > > https://wiki.php.net/rfc/autoload_classmap > > My initial reaction is (can you guess?): This can be done in userspace. function autoload_classmap(array $classes): void { spl_autoload_register(fn(string $class): void { if (isset($classes[$class])) require($classes[$class]); }); } This is essentially what composer already does for class maps, and it seems to work quite well there. However, I can see some small performance benefit from not having to invoke a userspace function (very small), so it's not wholly without merit. Where I have more issue is with case folding. I see three options: 1/ Require users to treat their class names as case-sensitive if they're going to use a class map. Personally, I like that this forces users away from case-insensitivity without breaking existing apps. 2/ Require users to pass a map with folded classnames. I expect the significant majority of users of this are using machine generated maps, so doing the case fold at "compile" time should be trivial. 3/ Allow any case in the map and fold it to lower at set time. This is the worst option IMO and no matter how it's implemented it's going to negate any performance gain it introduces. If someone *REALLY* wants that, they can map their array before invoking autoload_classmap(). This also forces them to make a decision about conflict resolution themselves. -Sara --000000000000cdccb405bdaae76b--