Re: [RFC] Autoloader Classmap

From: Date: Tue, 16 Mar 2021 17:46:04 +0000
Subject: Re: [RFC] Autoloader Classmap
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-113570@lists.php.net to get a copy of this message
On Tue, Mar 16, 2021 at 11:06 AM Harm Smits <harmsmitsdev@gmail.com> wrote:
>
> Hey,
>
> First time ever replying so hope all went well.
>
> I believe the autoload_set_classmap function's signature should change
> rather to something like this:
>
> ```
> /**
>  * Sets the internal autoloader to use the given classmap.
>  *
>  * @param $mapping key value pair of classes;
>  * @param $merge A boolean value indicating whether it should *merge* with
> an already defined classmap or override in its interity;
>  * @param $merge_override Whether existing keys in the classmap will be
> overridden.
>  *
>  * @return void
>  */
> autoload_set_classmap(array $mapping, bool $merge = true, bool
> $merge_override = false): void {}
> ```
>
> It makes more sense as some projects might have multiple composer projects
> loaded (think about modules in e.g. wordpress), where there can be multiple
> autoloaders. Hence the *$merge* and *$merge_override* variables. I don't
> know whether we should rather use flags for this, but considering named
> arguments are here now, I'd say it makes no sense to use them anymore
> (except for maybe consistency). Not sure about the implementation, but the
> features should be there for sure.
>
> Kind regards,
> Harm Smits

The proposed API allows users to fetch the current map and set a new
map. In other words, the callers can choose these decisions among
others (merge some keys, override others).


Thread (26 messages)

« previous php.internals (#113570) next »