Re: [RFC] Namespace-scoped declares, again
| From: | Rowan Collins | Date: | Tue, 13 Aug 2019 17:05:00 +0000 |
| Subject: | Re: [RFC] Namespace-scoped declares, again | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106567@lists.php.net to get a copy of this message | ||
On 13/08/2019 12:01, Mark Randall wrote:
On 13/08/2019 10:02, Rowan Collins wrote:This seems to be more complicated than Nicolas's version, and involve much more special magic, like the name __nsmeta, and the class that does nothing. I'm also not clear on how you're picturing the relationship between namespaces and packages. The way I understood the suggestion, you'd end up with something more like this, which feels much simpler and cleaner: # # File: /lib/company/project1/a/b/MyClass.php # <?php declare(package=company/project1); // or with a new keyword package company/project1; namespace company/project1/a/b; ... # # File: /lib/company/project1.php # <?php namespace company; class project1 extends \PHP\Package {I really like this approach. It allows a package definition file to exist, without either the language or the header of each file having to define its location.# # File: /lib/company/project1/a/b/MyClass.php # <?php declare_import(company[:label]); namespace company/project1/a/b; ... # # File: /lib/company/__nsmeta.php # <?php namespace company; namespace_declare [:label] {strict_types=1; strict_operators=1; upgrade_errors_to_exceptions=E_ALL;} final class __nsmeta {/* does nothing except be findable by the autoloader */ /* and defaults to private constructor so it can't be used */}
public function getParserDirectives() {
return [
'strict_types' => 1,
'strict_operators' => 1,
'upgrade_errors_to_exceptions' => E_ALL
];
}
}
Regards,
--
Rowan Collins
[IMSoP]