]> granicus.if.org Git - php/commitdiff
Prefer using declaring class rather than direct parent in error
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 21 Jan 2020 16:19:07 +0000 (17:19 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 21 Jan 2020 16:19:07 +0000 (17:19 +0100)
Point to the class that actually declares the property, which is
not necessarily the same as the direct parent class.

Zend/zend_inheritance.c

index ce55704ef7690fc3933b003fb37c0ace3fccd31a..6d14e6d573f2e93fd6812efbd80bf4821677ef39 100644 (file)
@@ -974,12 +974,12 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
                if (!(parent_info->flags & ZEND_ACC_PRIVATE)) {
                        if (UNEXPECTED((parent_info->flags & ZEND_ACC_STATIC) != (child_info->flags & ZEND_ACC_STATIC))) {
                                zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s%s::$%s as %s%s::$%s",
-                                       (parent_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ZSTR_VAL(ce->parent->name), ZSTR_VAL(key),
+                                       (parent_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ZSTR_VAL(parent_info->ce->name), ZSTR_VAL(key),
                                        (child_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ZSTR_VAL(ce->name), ZSTR_VAL(key));
                        }
 
                        if (UNEXPECTED((child_info->flags & ZEND_ACC_PPP_MASK) > (parent_info->flags & ZEND_ACC_PPP_MASK))) {
-                               zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::$%s must be %s (as in class %s)%s", ZSTR_VAL(ce->name), ZSTR_VAL(key), zend_visibility_string(parent_info->flags), ZSTR_VAL(ce->parent->name), (parent_info->flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
+                               zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::$%s must be %s (as in class %s)%s", ZSTR_VAL(ce->name), ZSTR_VAL(key), zend_visibility_string(parent_info->flags), ZSTR_VAL(parent_info->ce->name), (parent_info->flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
                        } else if ((child_info->flags & ZEND_ACC_STATIC) == 0) {
                                int parent_num = OBJ_PROP_TO_NUM(parent_info->offset);
                                int child_num = OBJ_PROP_TO_NUM(child_info->offset);
@@ -1004,7 +1004,7 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
                                                "Type of %s::$%s must not be defined (as in class %s)",
                                                ZSTR_VAL(ce->name),
                                                ZSTR_VAL(key),
-                                               ZSTR_VAL(ce->parent->name));
+                                               ZSTR_VAL(parent_info->ce->name));
                        }
                }
        } else {
@@ -1072,7 +1072,7 @@ static void do_inherit_class_constant(zend_string *name, zend_class_constant *pa
                c = (zend_class_constant*)Z_PTR_P(zv);
                if (UNEXPECTED((Z_ACCESS_FLAGS(c->value) & ZEND_ACC_PPP_MASK) > (Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PPP_MASK))) {
                        zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::%s must be %s (as in class %s)%s",
-                               ZSTR_VAL(ce->name), ZSTR_VAL(name), zend_visibility_string(Z_ACCESS_FLAGS(parent_const->value)), ZSTR_VAL(ce->parent->name), (Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PUBLIC) ? "" : " or weaker");
+                               ZSTR_VAL(ce->name), ZSTR_VAL(name), zend_visibility_string(Z_ACCESS_FLAGS(parent_const->value)), ZSTR_VAL(parent_const->ce->name), (Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PUBLIC) ? "" : " or weaker");
                }
        } else if (!(Z_ACCESS_FLAGS(parent_const->value) & ZEND_ACC_PRIVATE)) {
                if (Z_TYPE(parent_const->value) == IS_CONSTANT_AST) {