On 13 December 2017 at 05:04, Michał Brzuchalski <mic...@brzuchalski.com> wrote: > > If we're going to introduce someday a namespace file, then IMO it should not > be putted outside namespace folder. > For eg class Acme\Animal\Cat in src/Acme/Animal/Cat.php should have > namespace file in src/Acme/Aniimal/namespace.php > or even more src/Acme/Animal/ns.php > Why? Because users use PSR-4 so then they're src folder looks more like: > src/Cat.php <-- class Acme\Animal\Cat > src/ns.php <-- that should be then a place for namespace declare or even > function and constants.
You are right, my previous proposal src/Acme/Animal.namespace.php would not work universally. But your proposal, src/Acme/Animal/ns.php clashes with the class file for class \Acme\Animal\ns. We would need something other than NAME.php. E.g. src/Acme/Animal/ns.inc.php But then Composer would still need to make sure that this file is always included before any class files from this directory. On language level we cannot assume that Composer is being used, and that it is being used correctly. So again this would be fragile. > > Such namespace file can be a good place for namespace function and constants > declaration. > Also I think there is no need for another global function named > `namespace_declare` if we had namespace file > then we can utilise declare for that. > Lets imagine such syntax: > > // src/Acme/Animal/ns.php > <?php > > namespace Acme\Animal declare(strict_types=1,another_option=0); > const CAT = 1; > function createCat() : Cat {} This means you are changing the meaning of existing declare() to apply to the entire namespace? Or to the entire directory? Or maybe the difference here is that there is no semicolon directly after the namespace declaration? I am not convinced by this syntax. But even if we would find a good syntax, the behavioral problems pointed out by Stanislav still apply. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php