Commit 4d35f4a9c8f for php
commit 4d35f4a9c8fad06206390b2670515b10fea23800
Author: Gina Peter Banyard <girgias@php.net>
Date: Thu Oct 1 08:32:51 2026 +0100
Zend: use new zend_object_copy() API
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index f0b45a64ba9..4e2b407e912 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -4452,8 +4452,7 @@ ZEND_API void zend_get_callable_zval_from_fcc(const zend_fcall_info_cache *fcc,
} else if (fcc->function_handler->common.scope) {
array_init(callable);
if (fcc->object) {
- GC_ADDREF(fcc->object);
- add_next_index_object(callable, fcc->object);
+ add_next_index_object(callable, zend_object_copy(fcc->object));
} else {
add_next_index_str(callable, zend_string_copy(fcc->calling_scope->name));
}
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index c7279ea36e7..f5b88a33aa8 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -902,8 +902,7 @@ static void zend_create_closure_ex(
if (scope) {
closure->func.common.fn_flags |= ZEND_ACC_PUBLIC;
if (this_ptr && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) {
- closure->this_ptr = this_ptr;
- GC_ADDREF(this_ptr);
+ closure->this_ptr = zend_object_copy(this_ptr);
}
}
}
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 9c414634a23..e7923d76996 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -5222,8 +5222,8 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_o
call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
if (object) {
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
- GC_ADDREF(object); /* For $this pointer */
- object_or_called_scope = object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(object);
}
}
} else {
@@ -5311,8 +5311,8 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(const z
object_or_called_scope = object->ce;
} else {
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
- GC_ADDREF(object); /* For $this pointer */
- object_or_called_scope = object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(object);
}
}
} else {
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index c608b13cb25..a1b7c16ba73 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -873,8 +873,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_
} else {
object_or_called_scope = fci_cache->object;
call_info = ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_HAS_THIS;
- pinned_this = fci_cache->object;
- GC_ADDREF(pinned_this);
+ pinned_this = zend_object_copy(fci_cache->object);
}
if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_DEPRECATED)) {
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index b01d7287c53..efa05df6aa6 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -22,6 +22,8 @@
* php zend_vm_gen.php
*/
+#include "zend_objects_API.h"
+
ZEND_VM_HELPER(zend_add_helper, ANY, ANY, zval *op_1, zval *op_2)
{
USE_OPLINE
@@ -4011,8 +4013,8 @@ ZEND_VM_HANDLER(118, ZEND_INIT_USER_CALL, CONST, CONST|TMP|CV, NUM)
call_info |= ZEND_CALL_HAS_THIS;
}
} else if (fcc.object) {
- GC_ADDREF(fcc.object); /* For $this pointer */
- object_or_called_scope = fcc.object;
+ /* For $this pointer */
+ object_or_called_scope = zend_object_copy(fcc.object);
call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 352e6d9f692..243716bfe87 100644
Binary files a/Zend/zend_vm_execute.h and b/Zend/zend_vm_execute.h differ
diff --git a/Zend/zend_weakrefs.c b/Zend/zend_weakrefs.c
index ad0308f44e2..adb31dfc5c1 100644
--- a/Zend/zend_weakrefs.c
+++ b/Zend/zend_weakrefs.c
@@ -488,8 +488,7 @@ static HashTable *zend_weakmap_get_properties_for(zend_object *object, zend_prop
zval pair;
array_init(&pair);
- GC_ADDREF(obj);
- add_assoc_object(&pair, "key", obj);
+ add_assoc_object(&pair, "key", zend_object_copy(obj));
Z_TRY_ADDREF_P(val);
add_assoc_zval(&pair, "value", val);