Skip to content

Commit cc51bf8

Browse files
committed
Simplify to using prototype even for asymmetric visibility
1 parent 825ee3f commit cc51bf8

File tree

4 files changed

+7
-43
lines changed

4 files changed

+7
-43
lines changed

Zend/tests/asymmetric_visibility/gh19044.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@ class C2 extends P {
2020
var_dump(C2::foo(new C1));
2121

2222
?>
23-
--EXPECTF--
24-
Fatal error: Uncaught Error: Cannot modify protected(set) property C1::$foo from scope C2 in %s:%d
25-
Stack trace:
26-
#0 %s(%d): C2::foo(Object(C1))
27-
#1 {main}
28-
thrown in %s on line %d
23+
--EXPECT--
24+
int(43)

Zend/tests/property_hooks/gh19044-2.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,5 @@ class C2 extends C1 {
2222
var_dump(C2::foo(new GrandC1));
2323

2424
?>
25-
--EXPECTF--
26-
Fatal error: Uncaught Error: Cannot modify protected(set) property GrandC1::$foo from scope C2 in %s:%d
27-
Stack trace:
28-
#0 %s(%d): C2::foo(Object(GrandC1))
29-
#1 {main}
30-
thrown in %s on line %d
25+
--EXPECT--
26+
int(3)

Zend/tests/property_hooks/gh19044-5.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,5 @@ class C2 extends GP {
2424
var_dump(C2::foo(new C1));
2525

2626
?>
27-
--EXPECTF--
28-
Fatal error: Uncaught Error: Cannot modify protected(set) property C1::$foo from scope C2 in %s:%d
29-
Stack trace:
30-
#0 %s(%d): C2::foo(Object(C1))
31-
#1 {main}
32-
thrown in %s on line %d
27+
--EXPECT--
28+
int(3)

Zend/zend_object_handlers.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -286,30 +286,6 @@ static zend_never_inline int is_protected_compatible_scope(const zend_class_entr
286286
}
287287
/* }}} */
288288

289-
static int is_asymmetric_set_protected_property_compatible_scope(const zend_property_info *info, const zend_class_entry *scope) /* {{{ */
290-
{
291-
zend_class_entry *ce;
292-
/* we need to identify the common protected(set) ancestor: if the prototype has the protected(set), it's straightforward */
293-
if (info->prototype->flags & ZEND_ACC_PROTECTED_SET) {
294-
ce = info->prototype->ce;
295-
} else if (info->hooks && info->hooks[ZEND_PROPERTY_HOOK_SET]) {
296-
/* shortcut: the visibility of hooks cannot be overwritten */
297-
zend_function *hook = info->hooks[ZEND_PROPERTY_HOOK_SET];
298-
ce = zend_get_function_root_class(hook);
299-
} else {
300-
/* we do not have an easy way to find the ancestor which introduces the protected(set), let's iterate */
301-
do {
302-
ce = info->ce;
303-
if (!ce->parent->properties_info_table) {
304-
break;
305-
}
306-
info = ce->parent->properties_info_table[OBJ_PROP_TO_NUM(info->offset)];
307-
} while (info->flags & ZEND_ACC_PROTECTED_SET);
308-
}
309-
return is_protected_compatible_scope(ce, scope);
310-
}
311-
/* }}} */
312-
313289
static zend_never_inline zend_property_info *zend_get_parent_private_property(zend_class_entry *scope, const zend_class_entry *ce, zend_string *member) /* {{{ */
314290
{
315291
zval *zv;
@@ -609,7 +585,7 @@ ZEND_API bool ZEND_FASTCALL zend_asymmetric_property_has_set_access(const zend_p
609585
return true;
610586
}
611587
return EXPECTED((prop_info->flags & ZEND_ACC_PROTECTED_SET)
612-
&& is_asymmetric_set_protected_property_compatible_scope(prop_info, scope));
588+
&& is_protected_compatible_scope(prop_info->prototype->ce, scope));
613589
}
614590

615591
static void zend_property_guard_dtor(zval *el) /* {{{ */ {

0 commit comments

Comments
 (0)