Skip to content

Commit e1fda10

Browse files
committed
Link unbound simple classes (without parent/intefaces/traits) in first place.
1 parent b113f7e commit e1fda10

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

Zend/zend_compile.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,10 @@ ZEND_API zend_result do_bind_class(zval *lcname, zend_string *lc_parent_name) /*
11431143
return FAILURE;
11441144
}
11451145

1146+
if (ce->ce_flags & ZEND_ACC_LINKED) {
1147+
return SUCCESS;
1148+
}
1149+
11461150
ce = zend_do_link_class(ce, lc_parent_name, Z_STR_P(lcname));
11471151
if (!ce) {
11481152
/* Reload bucket pointer, the hash table may have been reallocated */
@@ -7517,31 +7521,36 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{
75177521
ce->ce_flags |= ZEND_ACC_TOP_LEVEL;
75187522
}
75197523

7520-
if (toplevel
7521-
/* We currently don't early-bind classes that implement interfaces or use traits */
7522-
&& !ce->num_interfaces && !ce->num_traits
7524+
/* We currently don't early-bind classes that implement interfaces or use traits */
7525+
if (!ce->num_interfaces && !ce->num_traits
75237526
&& !(CG(compiler_options) & ZEND_COMPILE_WITHOUT_EXECUTION)) {
7524-
if (extends_ast) {
7525-
zend_class_entry *parent_ce = zend_lookup_class_ex(
7526-
ce->parent_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
7527-
7528-
if (parent_ce
7529-
&& ((parent_ce->type != ZEND_INTERNAL_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES))
7530-
&& ((parent_ce->type != ZEND_USER_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) || (parent_ce->info.user.filename == ce->info.user.filename))) {
7531-
7532-
CG(zend_lineno) = decl->end_lineno;
7533-
if (zend_try_early_bind(ce, parent_ce, lcname, NULL)) {
7527+
if (toplevel) {
7528+
if (extends_ast) {
7529+
zend_class_entry *parent_ce = zend_lookup_class_ex(
7530+
ce->parent_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
7531+
7532+
if (parent_ce
7533+
&& ((parent_ce->type != ZEND_INTERNAL_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES))
7534+
&& ((parent_ce->type != ZEND_USER_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) || (parent_ce->info.user.filename == ce->info.user.filename))) {
7535+
7536+
CG(zend_lineno) = decl->end_lineno;
7537+
if (zend_try_early_bind(ce, parent_ce, lcname, NULL)) {
7538+
CG(zend_lineno) = ast->lineno;
7539+
zend_string_release(lcname);
7540+
return;
7541+
}
75347542
CG(zend_lineno) = ast->lineno;
7535-
zend_string_release(lcname);
7536-
return;
75377543
}
7538-
CG(zend_lineno) = ast->lineno;
7544+
} else if (EXPECTED(zend_hash_add_ptr(CG(class_table), lcname, ce) != NULL)) {
7545+
zend_string_release(lcname);
7546+
zend_build_properties_info_table(ce);
7547+
ce->ce_flags |= ZEND_ACC_LINKED;
7548+
return;
75397549
}
7540-
} else if (EXPECTED(zend_hash_add_ptr(CG(class_table), lcname, ce) != NULL)) {
7541-
zend_string_release(lcname);
7550+
} else if (!extends_ast) {
7551+
/* Link unbound simple class */
75427552
zend_build_properties_info_table(ce);
75437553
ce->ce_flags |= ZEND_ACC_LINKED;
7544-
return;
75457554
}
75467555
}
75477556

Zend/zend_inheritance.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,8 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
26252625
uint32_t i, j;
26262626
zval *zv;
26272627

2628+
ZEND_ASSERT(!(ce->ce_flags & ZEND_ACC_LINKED));
2629+
26282630
if (ce->parent_name) {
26292631
parent = zend_fetch_class_by_name(
26302632
ce->parent_name, lc_parent_name,

0 commit comments

Comments
 (0)