Re: [RFC] Namespace-scoped declares, again
| From: | Rowan Collins | Date: | Wed, 14 Aug 2019 10:26:34 +0000 |
| Subject: | Re: [RFC] Namespace-scoped declares, again | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106594@lists.php.net to get a copy of this message | ||
On 14/08/2019 11:17, Michał Brzuchalski wrote:
Following that would introduce unneeded additional directory hierarchy level in a usual library which uses PSR-4 which is the most used one, right? /composer.json /src/Foo.php /src/Foo/ <- all package classes should go here?That would be one place to put it, yes. But it would be entirely up to how people wanted to define their autoloader, that's the beauty of it. There's no reason something couldn't generate an autoloader that essentially said this: function autoload($name) { if ( $name == self::PACKAGE_NAME ) {
require self::SRC_DIR . '/__packagedef.php';} elseif ( str_begins_with($name, self::BASE_NAMESPACE) ) {
require self::SRC_DIR . str_replace('\\', '/', $name) . '.php';
}
}
Please don't pick holes in that implementation; my point is, if this was how packages were implemented, people would decide how they wanted to use it, and PSR-4 would probably be superseded by something which accounted for packages existing.
Regards,
--
Rowan Collins
[IMSoP]