Re: RFC Proposal - static modifier for classes
| From: | Stephen Reay | Date: | Fri, 24 Nov 2023 06:29:50 +0000 |
| Subject: | Re: RFC Proposal - static modifier for classes | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121796@lists.php.net to get a copy of this message | ||
> On 24 Nov 2023, at 01:09, Rowan Tommins <rowan.collins@gmail.com> wrote:
>
> 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.
>
I think attractive is the wrong word here, but yes in general the issue is that it becomes a
developer overhead as the number and location of files increases, particularly if you want to keep
the files organised in the filesystem in a similar fashion to classes (i.e. namespaces mapping to
directory names).
> 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).
>
I couldn't agree more - like I said at the start: I have no dog in this particular race about
static classes, my only concern is the continued use of Composer as a flimsy argument about why
features aren't required.
Cheers
Stephen
> Regards,
> --
> Rowan Tommins
> [IMSoP]