On 17/09/2020 13:28, Olle Härstedt wrote:
We have public, protected and private. Since PHP has no module system, we
have no qualifier to mark a class property as "private for this module".
One solution to this could be to add a new qualifier "internal", to make
properties public within the current namespace.


As well as the implementation details of doing this at run-time (which is where PHP does all its access checks right now) the mapping of "namespace" to "module" is not necessarily the most useful one.

For instance, if you define an "internal" property in a class called Acme\Frobulator\Handlers\TextFile\Format\CSV, it would be accessible in other classes in namespace Acme\Frobulator\Handlers\TextFile\Format\ and possibly also sub-namespaces like Acme\Frobulator\Handlers\TextFile\Format\Exceptions, but not in other parts of Acme\Frobulator\Handlers\TextFile or Acme\Frobulator as a whole.

If Acme\Frobulator was the root of the Composer package, the only way to make something internal to the package as a whole would be to flatten everything into that root namespace, like Acme\Frobulator\Handler_TextFile_Format_CSV

That leads me to think that if we do want "module"-level features - be it internal classes, internal properties, or module-level declare() settings - we need a way for the user to define that separately from the fully-qualified namespace.

Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

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

Reply via email to