Re: [RFC] Namespace-scoped declares, again

From: Date: Tue, 13 Aug 2019 11:01:53 +0000
Subject: Re: [RFC] Namespace-scoped declares, again
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-106566@lists.php.net to get a copy of this message
On 13/08/2019 10:02, Rowan Collins wrote:
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 */
} ... Caveat would be for situations that do not use an autoloader, the __nsmeta.php would need to be loaded first, this is something that PHP7.4 autoloaders would need to take into consideration. Mark Randall

« previous php.internals (#106566) next »