On 12/08/2019 09:17, Nicolas Grekas wrote:
Individual files could declare their package using this style:
<?php declare(package=MyVendor\MyPackage);

That would be enough to group a set of files together and make them share
eg some private classes, some optional PHP behaviors, etc.

The right side "MyVendor\MyPackage" would also be a FQCN that PHP would
autoload as a regular class. The corresponding class would then be the
place where ppl would declare the engine behavior they want for their
package (strict types, etc). To enforce this, the engine could require that
the "MyPackage" class implements some interface/extend some base abstract
class.


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.

Importantly, although it would trigger the autoloader if not yet defined, the package could be defined in advance, for instance as part of a preload directive. It could even be possible to define multiple packages in one file, or define them dynamically, using all the existing features of the language like require and eval.

On a bikeshedding note, I've never liked the way declare syntax looks, so would prefer a new keyword, but the symmetry of replacing <?php declare(strict_types=1); with <?php declare(package=Something\Defining\StrictOptions); is admittedly quite appealing.

Regards,

--
Rowan Collins
[IMSoP]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to