Skip to content

Commit 3d86d9a

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Add missing COMPILE_IGNORE_OTHER_FILES check for static calls
2 parents 9038823 + 1acd7a0 commit 3d86d9a

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ PHP NEWS
3030
- Opcache:
3131
. Fixed bug GH-13433 (Segmentation Fault in zend_class_init_statics when
3232
using opcache.preload). (nielsdos)
33+
. Fixed incorrect assumptions across compilation units for static calls.
34+
(ilutov)
3335

3436
- OpenSSL:
3537
. Fixed bug GH-10495 (feof on OpenSSL stream hangs indefinitely).

Zend/zend_compile.c

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4118,6 +4118,27 @@ static bool fbc_is_finalized(zend_function *fbc) {
41184118
return !ZEND_USER_CODE(fbc->type) || (fbc->common.fn_flags & ZEND_ACC_DONE_PASS_TWO);
41194119
}
41204120

4121+
static bool zend_compile_ignore_class(zend_class_entry *ce, zend_string *filename)
4122+
{
4123+
if (ce->type == ZEND_INTERNAL_CLASS) {
4124+
return CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES;
4125+
} else {
4126+
return (CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES)
4127+
&& ce->info.user.filename != filename;
4128+
}
4129+
}
4130+
4131+
static bool zend_compile_ignore_function(zend_function *fbc, zend_string *filename)
4132+
{
4133+
if (fbc->type == ZEND_INTERNAL_FUNCTION) {
4134+
return CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS;
4135+
} else {
4136+
return (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS)
4137+
|| ((CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES)
4138+
&& fbc->op_array.filename != filename);
4139+
}
4140+
}
4141+
41214142
static zend_result zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast, uint32_t num_args) /* {{{ */
41224143
{
41234144
zend_string *name, *lcname;
@@ -4132,11 +4153,9 @@ static zend_result zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast,
41324153
lcname = zend_string_tolower(name);
41334154

41344155
fbc = zend_hash_find_ptr(CG(function_table), lcname);
4135-
if (!fbc || !fbc_is_finalized(fbc)
4136-
|| (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
4137-
|| (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS))
4138-
|| (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) && fbc->op_array.filename != CG(active_op_array)->filename)
4139-
) {
4156+
if (!fbc
4157+
|| !fbc_is_finalized(fbc)
4158+
|| zend_compile_ignore_function(fbc, CG(active_op_array)->filename)) {
41404159
zend_string_release_ex(lcname, 0);
41414160
return FAILURE;
41424161
}
@@ -4646,11 +4665,9 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
46464665
return;
46474666
}
46484667

4649-
if (!fbc || !fbc_is_finalized(fbc)
4650-
|| (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
4651-
|| (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS))
4652-
|| (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) && fbc->op_array.filename != CG(active_op_array)->filename)
4653-
) {
4668+
if (!fbc
4669+
|| !fbc_is_finalized(fbc)
4670+
|| zend_compile_ignore_function(fbc, CG(active_op_array)->filename)) {
46544671
zend_string_release_ex(lcname, 0);
46554672
zend_compile_dynamic_call(result, &name_node, args_ast, ast->lineno);
46564673
return;
@@ -4817,7 +4834,11 @@ static void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type
48174834
if (opline->op1_type == IS_CONST) {
48184835
zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op1) + 1);
48194836
ce = zend_hash_find_ptr(CG(class_table), lcname);
4820-
if (!ce && CG(active_class_entry)
4837+
if (ce) {
4838+
if (zend_compile_ignore_class(ce, CG(active_op_array)->filename)) {
4839+
ce = NULL;
4840+
}
4841+
} else if (CG(active_class_entry)
48214842
&& zend_string_equals_ci(CG(active_class_entry)->name, lcname)) {
48224843
ce = CG(active_class_entry);
48234844
}
@@ -8162,9 +8183,7 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel)
81628183
ce->parent_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
81638184

81648185
if (parent_ce
8165-
&& ((parent_ce->type != ZEND_INTERNAL_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES))
8166-
&& ((parent_ce->type != ZEND_USER_CLASS) || !(CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) || (parent_ce->info.user.filename == ce->info.user.filename))) {
8167-
8186+
&& !zend_compile_ignore_class(parent_ce, ce->info.user.filename)) {
81688187
if (zend_try_early_bind(ce, parent_ce, lcname, NULL)) {
81698188
zend_string_release(lcname);
81708189
return;

0 commit comments

Comments
 (0)