Re: Explicit callee defaults

From: Date: Sat, 27 Jul 2024 08:42:30 +0000
Subject: Re: Explicit callee defaults
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
> On Jul 27, 2024, at 3:19 AM, Rob Landers <[email protected]> wrote:
> There’s nothing stopping you from doing that, except your autoloader. If you wanted to have
> every class ending with Arg load the same class without arg; so QueryArg and Query are usually in
> the same file (but can be in separate files too), you could do something like this:
> 
> <?php
> function customArgAutoloader($className) {
>     if (substr($className, -3) === 'Arg') {
>         $baseClass = substr($className, 0, -3);
>         $filePath = __DIR__ . '/' . $baseClass . '.php';
> 
>         if (file_exists($filePath)) {
>             require_once $filePath;
>         } 
>     }
> }
> 
> spl_autoload_register('customArgAutoloader');
> 
> (Untested, but you get the idea)

Sure, but that is non-standard, so it would be swimming against the current to use it, and no one
else would write code that way.

Still, the reason for my comment was to ask we consider a first-class args type which would enable
being able to pass parameters like {foo: 1, bar: 2} instead of  new
QueryArgs(foo: 1, bar: 2), not to discuss autoloaders.

-Mike



Thread (11 messages)

« previous php.internals (#124638) next »