On 02/08/2025 15:09, Rob Landers wrote:
I’m not sure what you mean? https://3v4l.org/WKILh#v8.4.10

There is clearly shadowing going on.


There's a lot of confusing code in that example, so I'm not really sure what it's illustrating.

This example seems more to the point: https://3v4l.org/FVhXa

Regardless of whether you look up the reflection property on the parent or the child, it points to the same slot for property 'v'

In contrast, the same reflection code for a private property finds both values stored in the object: https://3v4l.org/S7GmM

You can see the same result with var_dump (and serialize, and debug_zval_dump, ...): https://3v4l.org/FqecC


I think the relevant code is this, in zend_declare_typed_property: https://heap.space/xref/php-src/Zend/zend_API.c?r=78d96e94fa8e05dd59d03aa4891fa843ebc93ef8#4661

if (access_type & ZEND_ACC_PUBLIC) {
    property_info->name = zend_string_copy(name);
} else if (access_type & ZEND_ACC_PRIVATE) {
    property_info->name = zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(name), ZSTR_LEN(name), is_persistent_class(ce));
} else {
    ZEND_ASSERT(access_type & ZEND_ACC_PROTECTED);
    property_info->name = zend_mangle_property_name("*", 1, ZSTR_VAL(name), ZSTR_LEN(name), is_persistent_class(ce));
}

For a private name, the mangled name includes the class where it's defined, which is where the shadowing comes from: the final merged symbol table has two differently named slots.

But for a protected name, the prefix is just "*", so it's the same slot no matter how many times it appears in the hierarchy, just like for public properties (whose names aren't mangled at all).


How this relates back to the original example in the thread, I'm not sure, but it's definitely not "shadowing" in the same sense as a private property.

--
Rowan Tommins
[IMSoP]

Reply via email to