Make namespace part of runtime
| From: | Olle Härstedt | Date: | Fri, 27 Aug 2021 19:47:52 +0000 |
| Subject: | Make namespace part of runtime | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-115885@lists.php.net to get a copy of this message | ||
Hi,
As a followup for my previous post, I think this could be a good place
to start to enable attribute writers to create encapsulation mechanics
for composition, like namespace visibility, "internal" access or
friend classes.
There's an outline to an idea by Nikic here:
https://github.com/php/php-src/pull/947#issuecomment-224934615
> In principle this should be relatively simple: Introduce a struct _zend_namespace { zend_string
> *name, uint32_t start; uint32_t end; } structure (where start/end are opline offsets), and store an
> array of these in the op array. Usually this array will have only a single element (or be empty).
> Generating and storing this data should be relatively simple. The most difficult part is probably
> adding support for this structure in the opcache optimizer (particularly the block pass), but this
> can later be done by someone else, who is familiar with the component.
The missing part is exposing it to attribute authors using a magic
constant like __NAMESPACE_RUNTIME__, reflection, or something else I
didn't think of. :)
Eventually, idiomatic attributes could be made part of the core
language as new keywords, for performance reasons (instead of
#[Internal] attribute, add an "internal" keyword, and so on).
Good idea or bad?
Olle