On Mon, Dec 11, 2017 at 2:43 PM Nikita Popov <nikita....@gmail.com> wrote:

> Hi internals!
>
> Some time ago I introduced the following proposal for namespace-scoped
> declares:
>
>     https://wiki.php.net/rfc/namespace_scoped_declares
>
> The idea is to allow specifying declare directives for a whole library or
> project using:
>
>     namespace_declare('Vendor\Lib', ['strict_types' => 1]);
>
> I've finally gotten around to implementing this proposal (
> https://github.com/php/php-src/pull/2972) and would like to move forward
> with it.
>
> The reason why I'm picking it up again is some feedback I received for the
> explicit call-time send-by-ref proposal. The main objection seems to be
> that the feature has limited usefulness if it's optional rather than
> required, because you still can't be sure that something is a by-value
> pass, just because no & is present. At the same time, we can't make this
> required anytime soon due to the large BC impact.
>
> Namespace-scoped declares are perfectly suited to resolve this problem. We
> can introduce a require_explicit_send_by_ref declare directive to make the
> call-site annotation required, and libraries/projects can easily opt-in to
> it using namespace_declare(). There would be no BC impact, while at the
> same time projects could benefit from the additional clarity and
> performance improvements immediately.
>
> Thanks,
> Nikita
>

I plan to pick up this proposal again. I think the motivation here has
become more pressing in the meantime. The strict_operators proposal is
under discussion, and Rowan's "locked classes" essentially concluded with
"doing this with a declare is better". I also think that this proposal will
be helpful for the explicit call-site by-reference passing RFC.

Based on the received feedback, I plan to change this proposal from being
"namespace-scoped" to being "directory-scoped" instead. This should both
resolve some of the concerns and make the proposal more flexible: Not all
code sharing the same namespace is part of the same package (multiple
packages may have classes in the same namespace), or not of the same type
(code and tests may share a namespace) and sometimes people use incorrect
namespaces out of ignorance (e.g. place their own Doctrine models under the
Doctrine namespace). Making the declares apply to a directory avoids these
issues.

Nikita

Reply via email to