Commit 59dd0f8a48c for php.net

commit 59dd0f8a48c48fe17a0426d59716cf33858b810b
Author: Tim Düsterhus <tim@tideways-gmbh.com>
Date:   Tue Jul 1 20:24:11 2025 +0200

    Zend: Use `zend_bad_method_call()` when cloning from the wrong scope (#18999)

diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index fc3b0f57d85..48e0e86d3b2 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -93,11 +93,7 @@ ZEND_FUNCTION(clone)
 		if (clone->common.scope != scope) {
 			if (UNEXPECTED(clone->common.fn_flags & ZEND_ACC_PRIVATE)
 			 || UNEXPECTED(!zend_check_protected(zend_get_function_root_class(clone), scope))) {
-				zend_throw_error(NULL, "Call to %s %s::__clone() from %s%s",
-					zend_visibility_string(clone->common.fn_flags), ZSTR_VAL(clone->common.scope->name),
-					scope ? "scope " : "global scope",
-					scope ? ZSTR_VAL(scope->name) : ""
-				);
+				zend_bad_method_call(clone, clone->common.function_name, scope);
 				RETURN_THROWS();
 			}
 		}
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 5d8d9f4caeb..e1593cadce7 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -4123,15 +4123,6 @@ static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DAT
 	}
 }

-static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_clone_call(zend_function *clone, zend_class_entry *scope)
-{
-	zend_throw_error(NULL, "Call to %s %s::__clone() from %s%s",
-		zend_visibility_string(clone->common.fn_flags), ZSTR_VAL(clone->common.scope->name),
-		scope ? "scope " : "global scope",
-		scope ? ZSTR_VAL(scope->name) : ""
-	);
-}
-
 #if ZEND_INTENSIVE_DEBUGGING

 #define CHECK_SYMBOL_TABLES()													\
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 51aaf635b3b..9f7042386a1 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -6046,7 +6046,7 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
 		if (clone->common.scope != scope) {
 			if (UNEXPECTED(clone->common.fn_flags & ZEND_ACC_PRIVATE)
 			 || UNEXPECTED(!zend_check_protected(zend_get_function_root_class(clone), scope))) {
-				zend_wrong_clone_call(clone, scope);
+				zend_bad_method_call(clone, clone->common.function_name, scope);
 				FREE_OP1();
 				ZVAL_UNDEF(EX_VAR(opline->result.var));
 				HANDLE_EXCEPTION();
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index f29c6b47261..cb2af9e49dd 100644
Binary files a/Zend/zend_vm_execute.h and b/Zend/zend_vm_execute.h differ
diff --git a/tests/classes/factory_and_singleton_007.phpt b/tests/classes/factory_and_singleton_007.phpt
index fc232bdb865..6cf120e18be 100644
--- a/tests/classes/factory_and_singleton_007.phpt
+++ b/tests/classes/factory_and_singleton_007.phpt
@@ -17,4 +17,4 @@ protected function __clone() {

 ?>
 --EXPECT--
-Error: Call to protected test::__clone() from global scope
+Error: Call to protected method test::__clone() from global scope
diff --git a/tests/classes/factory_and_singleton_008.phpt b/tests/classes/factory_and_singleton_008.phpt
index 672c0832707..a23af647592 100644
--- a/tests/classes/factory_and_singleton_008.phpt
+++ b/tests/classes/factory_and_singleton_008.phpt
@@ -17,4 +17,4 @@ private function __clone() {

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