On 13/08/2019 23:28, Mark Randall wrote:
On 13/08/2019 21:26, Rowan Collins wrote:
Ah, that makes sense. Does that necessarily mean we need a dummy
class, though? The autoloading logic in the engine knows that it
called the autoload callback expecting a package definition, so can
count as success that the package is now defined.
In other words, the file the autoloader included would look like this
(again, sticking to the notion that "package" is separate from
"namespace"):
Personally with file-level opt ins I'm not 100% sold on the benefits
of packages over namespace level information. I guess I'm not certain
on what problem they're trying to solve that's different from just
another object at namespace level.
The problem they're trying to solve is that at the moment, there is no
namespace-level information. Namespaces form an arbitrarily deep
hierarchy, and don't need to be declared before they're used; it's hard
to retrofit configuration into that. In my mind a package would be very
similar to a namespace, but would have a mandatory declaration
somewhere, giving a place to define its settings and properties; and
there would be no "sub-packages", so no need to define inheritance and
over-rides.
As for the dummy class, the only real benefit is that existing
autoloading procedures can be used to locate it and be included with
minimal overhead.
PHP can call the autoloader internally but it would require userland
loaders to be upgraded with it, not exactly a huge stretch, especially
with most things being composer-based, but a dummy class would make it
work out the box, including optimization steps like dumping the class
list.
I see what you mean; but the change needed to autoloaders would be
pretty minimal: if they just turn the name into a file path and run
file_exists(), no change at all; if they tokenize files in advance to
build a class map, they would need to add "packagedef" to the list of
tokens to search for, alongside "class", "interface", and "trait". The
same change would be needed if we introduced a "struct" or "enum"
keyword, and I don't think anyone would expect to write dummy classes
alongside those.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php