On Thu, 23 Nov 2023 at 14:20, Stephen Reay <php-li...@koalephant.com> wrote:

>
> Out of the box, with no package manager or module loader or anything, you
> can do as little as call `spl_autoload_register` with no arguments, and
> have working class autoloading.
>


Sure, it's just about possible that you could paste that one line into each
of your PHP files, and they'd all pick up the right classes. But it's more
likely that you have some shared include called "startup.php",
"boostrap.php", "header.php", etc, which has that line plus a bunch of
other setup. So, the argument goes that adding a line "require
'namespace_foo_functions.php';" to that shared include isn't that big a
problem.

(If it happens you are using Composer, the files and config are listed in a
JSON file rather than a PHP one, and Composer generates the shared include,
but the logic's basically the same.)

The strongest counter-argument, I think, is that it *scales* badly: once
you have more than a handful of such include files, an autoloader solution
becomes more attractive than listing all the files.

However, in itself that's not an argument for static classes; it's an
argument for function autoloading; the argument for static classes needs to
be either:

- "admit it, we're never going to get function autoloading";
- or "I'd want this even if we had function autoloading" (in which case the
discussion of require vs autoloading becomes irrelevant).

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to