Skip to content

Commit 59dd0f8

Browse files
authored
Zend: Use zend_bad_method_call() when cloning from the wrong scope (#18999)
1 parent f71271d commit 59dd0f8

File tree

6 files changed

+8
-21
lines changed

6 files changed

+8
-21
lines changed

‎Zend/zend_builtin_functions.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ ZEND_FUNCTION(clone)
9393
if (clone->common.scope != scope) {
9494
if (UNEXPECTED(clone->common.fn_flags & ZEND_ACC_PRIVATE)
9595
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(clone), scope))) {
96-
zend_throw_error(NULL, "Call to %s %s::__clone() from %s%s",
97-
zend_visibility_string(clone->common.fn_flags), ZSTR_VAL(clone->common.scope->name),
98-
scope ? "scope " : "global scope",
99-
scope ? ZSTR_VAL(scope->name) : ""
100-
);
96+
zend_bad_method_call(clone, clone->common.function_name, scope);
10197
RETURN_THROWS();
10298
}
10399
}

‎Zend/zend_execute.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4123,15 +4123,6 @@ static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DAT
41234123
}
41244124
}
41254125

4126-
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_clone_call(zend_function *clone, zend_class_entry *scope)
4127-
{
4128-
zend_throw_error(NULL, "Call to %s %s::__clone() from %s%s",
4129-
zend_visibility_string(clone->common.fn_flags), ZSTR_VAL(clone->common.scope->name),
4130-
scope ? "scope " : "global scope",
4131-
scope ? ZSTR_VAL(scope->name) : ""
4132-
);
4133-
}
4134-
41354126
#if ZEND_INTENSIVE_DEBUGGING
41364127

41374128
#define CHECK_SYMBOL_TABLES() \

‎Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6046,7 +6046,7 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
60466046
if (clone->common.scope != scope) {
60476047
if (UNEXPECTED(clone->common.fn_flags & ZEND_ACC_PRIVATE)
60486048
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(clone), scope))) {
6049-
zend_wrong_clone_call(clone, scope);
6049+
zend_bad_method_call(clone, clone->common.function_name, scope);
60506050
FREE_OP1();
60516051
ZVAL_UNDEF(EX_VAR(opline->result.var));
60526052
HANDLE_EXCEPTION();

‎Zend/zend_vm_execute.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/classes/factory_and_singleton_007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ try {
1717

1818
?>
1919
--EXPECT--
20-
Error: Call to protected test::__clone() from global scope
20+
Error: Call to protected method test::__clone() from global scope

‎tests/classes/factory_and_singleton_008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ try {
1717

1818
?>
1919
--EXPECT--
20-
Error: Call to private test::__clone() from global scope
20+
Error: Call to private method test::__clone() from global scope

0 commit comments

Comments
 (0)