Re: RFC Proposal - static modifier for classes
| From: | Rowan Tommins | Date: | Thu, 23 Nov 2023 18:09:44 +0000 |
| Subject: | Re: RFC Proposal - static modifier for classes | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121785@lists.php.net to get a copy of this message | ||
On Thu, 23 Nov 2023 at 14:20, Stephen Reay <php-lists@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]