Re: [PHP-DEV] [RFC] Namespace-scoped declares, again

This is only part of a thread. view whole thread
  106568
August 13, 2019 17:45 markyr@gmail.com (Mark Randall)
On 13/08/2019 18:05, 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.
I was looking for a way that would be intuitive to the existing system. We already have an existing userland system for locating a class. By using a placeholder class we can locate it using our existing logic.
> class project1 extends \PHP\Package { >     public function getParserDirectives() { >         return [ >             'strict_types' => 1, >             'strict_operators' => 1, >             'upgrade_errors_to_exceptions' => E_ALL >         ]; >      } > }
I thought about this as my first consideration, however it effectively requires that the PHP code within the package class is fully parsed and executed in order for it to retrieve the data. Consider pre-loading where the code is compiled, but not run, it would not be possible to use namespace level defines to add compile-level optimizations or checks (at least without some AST hackery). Meanwhile, the compiler itself could pull out a namespace_declare block and fully understand the information in it without actually needing to run anything. If I was writing a runtime package system, I would absolutely do it in the way you suggest, and in fact I already do for my own packages which deal with wrapping up css / js / html template files. Perfect for runtime, not so good for compile time, but if I'm wrong I dare say someone will let me know. Mark Randall