Skip to content

Make "prototype" the function which inheritance is checked against #3993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ typedef struct _zend_oparray_context {
/* function is a destructor | | | */
#define ZEND_ACC_DTOR (1 << 29) /* | X | | */
/* | | | */
/* function is a destructor | | | */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is identical as the define above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, if this change is safe.
"prototype" is also used to check overridden protected method visibility.
If you change "prototype" meaning, this also changes visibility.

#define ZEND_ACC_HAS_ABSTRACT_PARENT (1 << 30) /* | X | | */
/* | | | */
/* op_array uses strict mode types | | | */
#define ZEND_ACC_STRICT_TYPES (1U << 31) /* | X | | */

Expand Down
25 changes: 10 additions & 15 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,27 +587,24 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
child->common.fn_flags |= ZEND_ACC_CHANGED;
}

if (parent_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_HAS_ABSTRACT_PARENT)) {
child->common.fn_flags |= ZEND_ACC_HAS_ABSTRACT_PARENT;
}

do {
if (!(parent_flags & ZEND_ACC_PRIVATE)) {
zend_function *proto = parent->common.prototype ?
parent->common.prototype : parent;

if (!(parent_flags & ZEND_ACC_CTOR)) {
if (!proto) {
proto = parent;
}
} else if (proto) {
if (parent_flags & ZEND_ACC_CTOR) {
/* ctors only have a prototype if is abstract (or comes from an interface) */
/* and if that is the case, we want to check inheritance against it */
zend_function *proto = parent->common.prototype
? parent->common.prototype : parent;
if (proto->common.fn_flags & ZEND_ACC_ABSTRACT) {
parent = proto;
} else {
break;
}
} else {
break;
}
if (child_zv && child->common.prototype != proto) {
if (child_zv && child->common.prototype != parent) {
do {
if (child->common.scope != ce
&& child->type == ZEND_USER_FUNCTION
Expand All @@ -622,7 +619,7 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
Z_PTR_P(child_zv) = child = new_function;
}
}
child->common.prototype = proto;
child->common.prototype = parent;
} while (0);
}
/* Prevent derived classes from restricting access that was available in parent classes (except deriving from non-abstract ctors) */
Expand All @@ -638,9 +635,7 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
zend_string *method_prototype = zend_get_function_declaration(parent);
zend_string *child_prototype = zend_get_function_declaration(child);

if (child->common.prototype && (
child->common.prototype->common.fn_flags & ZEND_ACC_ABSTRACT
)) {
if (child->common.fn_flags & ZEND_ACC_HAS_ABSTRACT_PARENT) {
error_level = E_COMPILE_ERROR;
error_verb = "must";
} else if ((parent->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) &&
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/tests/ReflectionClass_toString_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Class [ <user> class D extends C ] {
}

- Methods [1] {
Method [ <user, overwrites B, prototype A> public method f ] {
Method [ <user, overwrites B, prototype B> public method f ] {
@@ %s 12 - 12
}
}
Expand Down