Commit 5212b816d2b for php.net
commit 5212b816d2b0dd6dce9e49ba0cf2d209aa17995b
Author: Tim Düsterhus <tim@tideways-gmbh.com>
Date: Tue May 19 14:16:03 2026 +0200
zend_objects: Make old_object a const* in `zend_objects_clone_members()` (#22089)
* zend_objects: Make `old_object` a `const*` in `zend_objects_clone_members()`
* tree-wide: Make the original object `const` in `clone_obj` handlers
diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c
index 9fe46b6b6d2..2fc264742cd 100644
--- a/Zend/zend_objects.c
+++ b/Zend/zend_objects.c
@@ -193,14 +193,14 @@ ZEND_API zend_object* ZEND_FASTCALL zend_objects_new(zend_class_entry *ce)
return object;
}
-ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object, zend_object *old_object)
+ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object, const zend_object *old_object)
{
bool has_clone_method = old_object->ce->clone != NULL;
if (old_object->ce->default_properties_count) {
- zval *src = old_object->properties_table;
+ const zval *src = old_object->properties_table;
zval *dst = new_object->properties_table;
- zval *end = src + old_object->ce->default_properties_count;
+ const zval *end = src + old_object->ce->default_properties_count;
do {
i_zval_ptr_dtor(dst);
diff --git a/Zend/zend_objects.h b/Zend/zend_objects.h
index 44a8038a0fa..0930fa04310 100644
--- a/Zend/zend_objects.h
+++ b/Zend/zend_objects.h
@@ -24,7 +24,7 @@
BEGIN_EXTERN_C()
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce);
ZEND_API zend_object* ZEND_FASTCALL zend_objects_new(zend_class_entry *ce);
-ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object, zend_object *old_object);
+ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object, const zend_object *old_object);
ZEND_API void zend_object_std_dtor(zend_object *object);
ZEND_API void zend_objects_destroy_object(zend_object *object);
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index c77489af1b0..fc4a18e455c 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1831,7 +1831,7 @@ static zend_object *date_object_new_date(zend_class_entry *class_type) /* {{{ */
static zend_object *date_object_clone_date(zend_object *this_ptr) /* {{{ */
{
- php_date_obj *old_obj = php_date_obj_from_obj(this_ptr);
+ const php_date_obj *old_obj = php_date_obj_from_obj(this_ptr);
php_date_obj *new_obj = php_date_obj_from_obj(date_object_new_date(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
@@ -1988,7 +1988,7 @@ static zend_object *date_object_new_timezone(zend_class_entry *class_type) /* {{
static zend_object *date_object_clone_timezone(zend_object *this_ptr) /* {{{ */
{
- php_timezone_obj *old_obj = php_timezone_obj_from_obj(this_ptr);
+ const php_timezone_obj *old_obj = php_timezone_obj_from_obj(this_ptr);
php_timezone_obj *new_obj = php_timezone_obj_from_obj(date_object_new_timezone(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
@@ -2131,7 +2131,7 @@ static zend_object *date_object_new_interval(zend_class_entry *class_type) /* {{
static zend_object *date_object_clone_interval(zend_object *this_ptr) /* {{{ */
{
- php_interval_obj *old_obj = php_interval_obj_from_obj(this_ptr);
+ const php_interval_obj *old_obj = php_interval_obj_from_obj(this_ptr);
php_interval_obj *new_obj = php_interval_obj_from_obj(date_object_new_interval(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
@@ -2222,7 +2222,7 @@ static zend_object *date_object_new_period(zend_class_entry *class_type) /* {{{
static zend_object *date_object_clone_period(zend_object *this_ptr) /* {{{ */
{
- php_period_obj *old_obj = php_period_obj_from_obj(this_ptr);
+ const php_period_obj *old_obj = php_period_obj_from_obj(this_ptr);
php_period_obj *new_obj = php_period_obj_from_obj(date_object_new_period(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 2a0726b61bc..ef06d0fda30 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -283,7 +283,7 @@ static HashTable *gmp_get_debug_info(zend_object *obj, int *is_temp) /* {{{ */
static zend_object *gmp_clone_obj(zend_object *obj) /* {{{ */
{
- gmp_object *old_object = GET_GMP_OBJECT_FROM_OBJ(obj);
+ const gmp_object *old_object = GET_GMP_OBJECT_FROM_OBJ(obj);
gmp_object *new_object = GET_GMP_OBJECT_FROM_OBJ(gmp_create_object(obj->ce));
zend_objects_clone_members( &new_object->std, &old_object->std);
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index 248f5ba8b0e..96adc561c22 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -1397,7 +1397,7 @@ static void php_hashcontext_free(zend_object *obj) {
/* {{{ php_hashcontext_clone */
static zend_object *php_hashcontext_clone(zend_object *zobj) {
- php_hashcontext_object *oldobj = php_hashcontext_from_object(zobj);
+ const php_hashcontext_object *oldobj = php_hashcontext_from_object(zobj);
zend_object *znew = php_hashcontext_create(zobj->ce);
php_hashcontext_object *newobj = php_hashcontext_from_object(znew);
diff --git a/ext/intl/breakiterator/breakiterator_class.cpp b/ext/intl/breakiterator/breakiterator_class.cpp
index 7b6a59d839f..4d5793696cb 100644
--- a/ext/intl/breakiterator/breakiterator_class.cpp
+++ b/ext/intl/breakiterator/breakiterator_class.cpp
@@ -96,7 +96,7 @@ static int BreakIterator_compare_objects(zval *object1,
/* {{{ clone handler for BreakIterator */
static zend_object *BreakIterator_clone_obj(zend_object *object)
{
- BreakIterator_object *bio_orig = php_intl_breakiterator_fetch_object(object);
+ const BreakIterator_object *bio_orig = php_intl_breakiterator_fetch_object(object);
zend_object *ret_val = BreakIterator_ce_ptr->create_object(object->ce);
BreakIterator_object *bio_new = php_intl_breakiterator_fetch_object(ret_val);
diff --git a/ext/intl/calendar/calendar_class.cpp b/ext/intl/calendar/calendar_class.cpp
index 9ec9e617cb4..63b203d08d4 100644
--- a/ext/intl/calendar/calendar_class.cpp
+++ b/ext/intl/calendar/calendar_class.cpp
@@ -77,7 +77,7 @@ U_CFUNC void calendar_object_construct(zval *object,
/* {{{ clone handler for Calendar */
static zend_object *Calendar_clone_obj(zend_object *object)
{
- Calendar_object *co_orig = php_intl_calendar_fetch_object(object);
+ const Calendar_object *co_orig = php_intl_calendar_fetch_object(object);
zend_object *ret_val = Calendar_ce_ptr->create_object(object->ce);
Calendar_object *co_new = php_intl_calendar_fetch_object(ret_val);
diff --git a/ext/intl/converter/converter.cpp b/ext/intl/converter/converter.cpp
index 430d58c8f02..597746b8fac 100644
--- a/ext/intl/converter/converter.cpp
+++ b/ext/intl/converter/converter.cpp
@@ -934,7 +934,8 @@ static zend_object *php_converter_create_object(zend_class_entry *ce) {
}
static zend_object *php_converter_clone_object(zend_object *object) {
- php_converter_object *objval, *oldobj = php_converter_fetch_object(object);
+ const php_converter_object *oldobj = php_converter_fetch_object(object);
+ php_converter_object *objval;
zend_object *retval = php_converter_object_ctor(object->ce, &objval);
UErrorCode error = U_ZERO_ERROR;
diff --git a/ext/intl/dateformat/dateformat_class.cpp b/ext/intl/dateformat/dateformat_class.cpp
index 2ee2c454030..e9869612b87 100644
--- a/ext/intl/dateformat/dateformat_class.cpp
+++ b/ext/intl/dateformat/dateformat_class.cpp
@@ -66,7 +66,7 @@ zend_object *IntlDateFormatter_object_create(zend_class_entry *ce)
/* {{{ IntlDateFormatter_object_clone */
zend_object *IntlDateFormatter_object_clone(zend_object *object)
{
- IntlDateFormatter_object *dfo = php_intl_dateformatter_fetch_object(object);
+ const IntlDateFormatter_object *dfo = php_intl_dateformatter_fetch_object(object);
zend_object *new_obj = IntlDateFormatter_ce_ptr->create_object(object->ce);
IntlDateFormatter_object *new_dfo = php_intl_dateformatter_fetch_object(new_obj);
diff --git a/ext/intl/dateformat/datepatterngenerator_class.cpp b/ext/intl/dateformat/datepatterngenerator_class.cpp
index b58dc38ce82..4a137d916f1 100644
--- a/ext/intl/dateformat/datepatterngenerator_class.cpp
+++ b/ext/intl/dateformat/datepatterngenerator_class.cpp
@@ -36,7 +36,7 @@ zend_object_handlers IntlDatePatternGenerator_handlers;
static zend_object *IntlDatePatternGenerator_object_clone(zend_object *object)
{
- IntlDatePatternGenerator_object *dtpgo_orig = php_intl_datepatterngenerator_fetch_object(object);
+ const IntlDatePatternGenerator_object *dtpgo_orig = php_intl_datepatterngenerator_fetch_object(object);
zend_object *ret_val = IntlDatePatternGenerator_ce_ptr->create_object(object->ce);
IntlDatePatternGenerator_object *dtpgo_new = php_intl_datepatterngenerator_fetch_object(ret_val);
diff --git a/ext/intl/formatter/formatter_class.cpp b/ext/intl/formatter/formatter_class.cpp
index 7391a1cd9f6..5b82b53c6d6 100644
--- a/ext/intl/formatter/formatter_class.cpp
+++ b/ext/intl/formatter/formatter_class.cpp
@@ -62,7 +62,7 @@ U_CFUNC zend_object *NumberFormatter_object_create(zend_class_entry *ce)
/* {{{ NumberFormatter_object_clone */
U_CFUNC zend_object *NumberFormatter_object_clone(zend_object *object)
{
- NumberFormatter_object *nfo = php_intl_number_format_fetch_object(object);
+ const NumberFormatter_object *nfo = php_intl_number_format_fetch_object(object);
zend_object *new_obj = NumberFormatter_ce_ptr->create_object(object->ce);
NumberFormatter_object *new_nfo = php_intl_number_format_fetch_object(new_obj);
diff --git a/ext/intl/msgformat/msgformat_class.cpp b/ext/intl/msgformat/msgformat_class.cpp
index ef1a3fd8ec3..c4d74924b04 100644
--- a/ext/intl/msgformat/msgformat_class.cpp
+++ b/ext/intl/msgformat/msgformat_class.cpp
@@ -58,7 +58,7 @@ U_CFUNC zend_object *MessageFormatter_object_create(zend_class_entry *ce)
/* {{{ MessageFormatter_object_clone */
U_CFUNC zend_object *MessageFormatter_object_clone(zend_object *object)
{
- MessageFormatter_object *mfo = php_intl_messageformatter_fetch_object(object);
+ const MessageFormatter_object *mfo = php_intl_messageformatter_fetch_object(object);
zend_object *new_obj = MessageFormatter_ce_ptr->create_object(object->ce);
MessageFormatter_object *new_mfo = php_intl_messageformatter_fetch_object(new_obj);
diff --git a/ext/intl/spoofchecker/spoofchecker_class.cpp b/ext/intl/spoofchecker/spoofchecker_class.cpp
index 2d23aee677c..6f072081fa7 100644
--- a/ext/intl/spoofchecker/spoofchecker_class.cpp
+++ b/ext/intl/spoofchecker/spoofchecker_class.cpp
@@ -63,7 +63,7 @@ U_CFUNC zend_object *Spoofchecker_object_create(zend_class_entry *ce)
static zend_object *spoofchecker_clone_obj(zend_object *object) /* {{{ */
{
- Spoofchecker_object *spoofchecker_orig = php_intl_spoofchecker_fetch_object(object);
+ const Spoofchecker_object *spoofchecker_orig = php_intl_spoofchecker_fetch_object(object);
zend_object *new_obj_val = Spoofchecker_ce_ptr->create_object(object->ce);
Spoofchecker_object *spoofchecker_new = php_intl_spoofchecker_fetch_object(new_obj_val);
diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp
index 0d29a47c186..319e81c9a77 100644
--- a/ext/intl/timezone/timezone_class.cpp
+++ b/ext/intl/timezone/timezone_class.cpp
@@ -207,7 +207,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(
/* {{{ clone handler for TimeZone */
static zend_object *TimeZone_clone_obj(zend_object *object)
{
- TimeZone_object *to_orig = php_intl_timezone_fetch_object(object);
+ const TimeZone_object *to_orig = php_intl_timezone_fetch_object(object);
zend_object *ret_val = TimeZone_ce_ptr->create_object(object->ce);
TimeZone_object *to_new = php_intl_timezone_fetch_object(ret_val);
diff --git a/ext/intl/transliterator/transliterator_class.cpp b/ext/intl/transliterator/transliterator_class.cpp
index f261efb57ed..737c51fcf4d 100644
--- a/ext/intl/transliterator/transliterator_class.cpp
+++ b/ext/intl/transliterator/transliterator_class.cpp
@@ -130,7 +130,7 @@ static zend_object *Transliterator_object_create( zend_class_entry *ce )
/* {{{ clone handler for Transliterator */
static zend_object *Transliterator_clone_obj( zend_object *object )
{
- Transliterator_object *to_orig = php_intl_transliterator_fetch_object(object);
+ const Transliterator_object *to_orig = php_intl_transliterator_fetch_object(object);
zend_object *ret_val = Transliterator_ce_ptr->create_object(object->ce);
Transliterator_object *to_new = php_intl_transliterator_fetch_object(ret_val);
diff --git a/ext/random/random.c b/ext/random/random.c
index 81d0172748d..bd6f9f8a901 100644
--- a/ext/random/random.c
+++ b/ext/random/random.c
@@ -273,7 +273,7 @@ PHPAPI void php_random_engine_common_free_object(zend_object *object)
PHPAPI zend_object *php_random_engine_common_clone_object(zend_object *object)
{
- php_random_engine *old_engine = php_random_engine_from_obj(object);
+ const php_random_engine *old_engine = php_random_engine_from_obj(object);
php_random_engine *new_engine = php_random_engine_from_obj(old_engine->std.ce->create_object(old_engine->std.ce));
new_engine->engine.algo = old_engine->engine.algo;
diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c
index d25c310ed0d..4cf6e970b07 100644
--- a/ext/uri/php_uri.c
+++ b/ext/uri/php_uri.c
@@ -1034,7 +1034,7 @@ PHPAPI void php_uri_object_handler_free(zend_object *object)
PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object)
{
- php_uri_object *uri_object = php_uri_object_from_obj(object);
+ const php_uri_object *uri_object = php_uri_object_from_obj(object);
ZEND_ASSERT(uri_object->uri != NULL);