On 27/07/2019 09:33, Rasmus Schultz wrote:
On Thu, Jul 25, 2019 at 3:34 PM Nikita Popov <nikita....@gmail.com> wrote:
Based on the received feedback, I plan to change this proposal from being
"namespace-scoped" to being "directory-scoped" instead

Personally I'm not a huge fan of using implicit hierarchical directories for managing defines.

It's certainly better than global state functions, but in general I don't feel comfortable with the idea that an arbitrary file can effect the behaviour of the VM for particular files that does not directly reference it.

Obviously there's lots of functions that do that, set_error_handler etc, but I think it is best avoided wherever possible.

I think what the situation calls for is the PHP equivalent of #include - we need to be able to explicitly import the definitions from another file.

====== MyProject\Models\Test\SomeClass.php =======
```
<?php
import_declares(\MyProject);

namespace MyProject\Models\Test

class SomeClass {
  public function action(&$ref) { ... }
}
```

====== MyProject\declares.inc =======
```
<?php
declare(strict_types=1)
declare(call_site_references=1)
declare(global_function_fallback=0)
```

This forms an explicit link between the file and the declarations.

Clearly the question is "how to locate that file" as we don't want to return to the days of having to add relative file paths to every file.

An option which immediately comes to mind would be a new autoloader routine that maps namespaces to PSR4 physical directories. Sounds like a job for composer tbh so userland workload would be limited for projects using modern workflows.

This would of course be dependent on if the compiler stage has the ability to branch off and call an autoloader the first time it encounters the import_declares.

Just my 2 pence worth.

--
Mark Randall

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

Reply via email to