Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113554 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3764 invoked from network); 16 Mar 2021 03:04:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 03:04:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 47F041804F6 for ; Mon, 15 Mar 2021 19:57:48 -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=-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-Virus: No X-Envelope-From: Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (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, 15 Mar 2021 19:57:47 -0700 (PDT) Received: by mail-qk1-f196.google.com with SMTP id l132so33905363qke.7 for ; Mon, 15 Mar 2021 19:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=P3+sEL+v47PHf8S2zU2L980n9ndS2ZH6OKk+/EhORcs=; b=v+AxqgndWtYz+kru+Bob+6N0N/AJEIg03boTjw/TfLfGyCy1Zs0NbIvIYYuRK0gc7p 87SEkKCONoZOmyj8h+OkxtEjgSogeo8ZJbE83d9R5q9hXeHvvzLo03A3BbxZNdvyRKgR ruJ1C5Sq01hH45C9Uv7mMcltArJe8E8VlKpaZIKRCaLaDFs3JByJg42uBQ22IP3+Q7j5 GAJ1R3X7djniXesf7kzXceF5DMVMrIx+NYSJQAkwlZSzrAGQCowYjKh0jU2KIrJSgUnf gVAk4hgoPeM40trBdFpFsyglpeCxtCMip5WnO8vIodOMShKr30uwNNivwdWy4v1m5KKP QFkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=P3+sEL+v47PHf8S2zU2L980n9ndS2ZH6OKk+/EhORcs=; b=DRFgoIbwCu/NMjCAUXimplOtmQyXnHHB1RMCW4zfnS1JVAKEtKpFYpeznwfUko8mPh R99J1FFAaGONkO2X9KmLeFqGn9fWi6Wx3g0iXXH3GaYJfv4SFkSD3OfULCL8a2QuiNdF K/KgMkKmZRkj4fEKHzyCmIG1OTlgRYokEQGwK490hTsAHmvPxIIvtGkKDNdD+lTvplwa /MRU0Zsg5yjJP+vGtTjkZ5XuGk4TWrmnaTaRZssWyOie/p/hP1G7gII73PZKNhwAL+25 9f/4wxphPVM3iYwaZ2dzFQH9O9x3TFV5zWv3byLVtcJVZ7HrqLqCVfZXC4Bn5fQQB/4n TroQ== X-Gm-Message-State: AOAM531+bwY1nKjeeIwykhFi70H2YjkXaE0qaN36ujQ6AUWPi7RQgcMl cBqZtvwn5gzEx5NolxM9A9+wtqHRAz+OkFG3 X-Google-Smtp-Source: ABdhPJz2pv5ZIIao88VR35WWkosy91vTWE6at3WaWcs2BZMFCly6dPFOuSUEprGqJnyqkb5TXZT9Ew== X-Received: by 2002:a05:620a:14b3:: with SMTP id x19mr28631529qkj.384.1615863464315; Mon, 15 Mar 2021 19:57:44 -0700 (PDT) Received: from [192.168.1.239] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id 19sm13958252qkv.95.2021.03.15.19.57.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Mar 2021 19:57:43 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_5AB43497-3E70-4BDA-9EDF-44C8F24089AE" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Mon, 15 Mar 2021 22:57:43 -0400 In-Reply-To: <604f9c5c.1c69fb81.3093.e541SMTPIN_ADDED_MISSING@mx.google.com> Cc: internals@lists.php.net To: Mark Randall References: <604f9c5c.1c69fb81.3093.e541SMTPIN_ADDED_MISSING@mx.google.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Autoloader Classmap From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_5AB43497-3E70-4BDA-9EDF-44C8F24089AE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Mar 15, 2021, at 1:41 PM, Mark Randall wrote: >=20 > Hi Internals, >=20 > 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. >=20 > https://wiki.php.net/rfc/autoload_classmap Yes, please! This would be a real treat for those whose use-cases do = not fit nicely into the PSR-4 standard (like WordPress plugins.) However, may I discuss some additions? ----------- 1. Sometimes it is inconvenient to set the entire class-map. For = example, a WordPress plugin might want to add all of its files to the = autoloader and let other plugins handle their own needs. =20 While that could be done with your get() and set() functions along with = an array merge, it would be clearer in userland just to have an add(). =20= Further, when there are tens of plugins then adding the files for each = plugin could be a lot of userland array manipulation that I assume could = be done more efficiently within a core function. So, I would propose including a third function that would add to the = current classmap rather than just replace it like set(): autoload_add_classmap(mapping $array): void {} ----------- 2. There has been numerous times when I wanted to monitor when classes = are loaded. I have been reduced to calling get_declared_classes() before = require_once() and then call get_declared_classes() again after and = slice off the difference between the two, which I assume is very costly.=20= If would be great is the autoloader could call a callable and pass the = list of classes that were loaded, assuming such as callable exists. So, I would propose including a third function that would add to the = current classmap rather than just replace it like set(): autoload_set_classmap_listener(callable $listener): void {} autoload_get_classmap_listener(): callable {} This might be tangential to your RFC but if we are updating the = autoloader already this addition might be trivial.=20 ----------- 3. Based upon the above and the existing spl_*() functions I would ask = it it would not make sense to create an interface called "Loader" and a = set of classes to support autoloading instead, and then deprecate the = spl_*() at some distant point in the future? =20 To provide something to make it easier to consider this approach I = created a strawman Gist using PHP code to illustrate the idea. It is not = a complete working example, and likely not fully fleshed out either, but = it should work as a starting point for discussion:=20 https://gist.github.com/mikeschinkel/2ff8b5f78e88688dbbadb41a762c119f = Note that using an interface like this would allow developers to create = their own custom autoloaders as classes and/or we could implement a = PSR-4 specific autoloader class in the future directly in core that = could work with this configuration (and maybe even a PSR-1 autoloader in = core.) -Mike P.S. The interface and classes example uses the controversial "PHP" = namespace, but please let us not fixate on that. Let us instead discuss = if an interface and set of classes makes sense and if so figure out the = right namespace afterwards. --Apple-Mail=_5AB43497-3E70-4BDA-9EDF-44C8F24089AE--