Commit 4bfa1b64b0f for php.net

commit 4bfa1b64b0f328cfc93d636b09725a0c9bb84572
Author: Gina Peter Banyard <girgias@php.net>
Date:   Wed Mar 25 13:30:34 2026 +0000

    ext/spl: add const qualifiers when dealing with CEs (#21512)

diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index e705a1e303a..0c64d815dc8 100644
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -64,7 +64,7 @@ static zend_class_entry * spl_find_ce_by_name(zend_string *name, bool autoload)
 PHP_FUNCTION(class_parents)
 {
 	zval *obj;
-	zend_class_entry *parent_class, *ce;
+	zend_class_entry *ce;
 	bool autoload = true;

 	/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
@@ -86,7 +86,7 @@ PHP_FUNCTION(class_parents)
 	}

 	array_init(return_value);
-	parent_class = ce->parent;
+	const zend_class_entry *parent_class = ce->parent;
 	while (parent_class) {
 		spl_add_class_name(return_value, parent_class, 0, 0);
 		parent_class = parent_class->parent;
@@ -99,7 +99,7 @@ PHP_FUNCTION(class_implements)
 {
 	zval *obj;
 	bool autoload = true;
-	zend_class_entry *ce;
+	const zend_class_entry *ce;

 	/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
@@ -128,7 +128,7 @@ PHP_FUNCTION(class_uses)
 {
 	zval *obj;
 	bool autoload = true;
-	zend_class_entry *ce;
+	const zend_class_entry *ce;

 	/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index 3d6870a7ee9..efbe331104a 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -157,7 +157,7 @@ static void spl_array_object_free_storage(zend_object *object)
 static zend_object *spl_array_object_new_ex(zend_class_entry *class_type, zend_object *orig, int clone_orig)
 {
 	spl_array_object *intern;
-	zend_class_entry *parent = class_type;
+	const zend_class_entry *parent = class_type;
 	int inherited = 0;

 	intern = zend_object_alloc(sizeof(spl_array_object), parent);
diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c
index 5eceff88dfa..c72cae38a9c 100644
--- a/ext/spl/spl_dllist.c
+++ b/ext/spl/spl_dllist.c
@@ -304,7 +304,7 @@ static void spl_dllist_object_free_storage(zend_object *object) /* {{{ */
 static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zend_object *orig, int clone_orig) /* {{{ */
 {
 	spl_dllist_object *intern;
-	zend_class_entry  *parent = class_type;
+	const zend_class_entry *parent = class_type;
 	int                inherited = 0;

 	intern = zend_object_alloc(sizeof(spl_dllist_object), parent);
@@ -316,7 +316,7 @@ static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zend_
 	intern->traverse_position = 0;

 	if (orig) {
-		spl_dllist_object *other = spl_dllist_from_obj(orig);
+		const spl_dllist_object *other = spl_dllist_from_obj(orig);

 		if (clone_orig) {
 			intern->llist = spl_ptr_llist_init();
diff --git a/ext/spl/spl_functions.c b/ext/spl/spl_functions.c
index e7ecbc33f92..7b7991a1217 100644
--- a/ext/spl/spl_functions.c
+++ b/ext/spl/spl_functions.c
@@ -21,12 +21,12 @@
 #include "php.h"

 /* {{{ spl_add_class_name */
-void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
+void spl_add_class_name(zval *list, const zend_class_entry *pce, int allow, int ce_flags)
 {
 	if (!allow || (allow > 0 && (pce->ce_flags & ce_flags)) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
-		zval *tmp;
+		const zval *tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name);

-		if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
+		if (tmp == NULL) {
 			zval t;
 			ZVAL_STR_COPY(&t, pce->name);
 			zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
@@ -36,7 +36,7 @@ void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_fla
 /* }}} */

 /* {{{ spl_add_interfaces */
-void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
+void spl_add_interfaces(zval *list, const zend_class_entry *pce, int allow, int ce_flags)
 {
 	if (pce->num_interfaces) {
 		ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED);
@@ -48,12 +48,10 @@ void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_fl
 /* }}} */

 /* {{{ spl_add_traits */
-void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
+void spl_add_traits(zval *list, const zend_class_entry *pce, int allow, int ce_flags)
 {
-	zend_class_entry *trait;
-
 	for (uint32_t num_traits = 0; num_traits < pce->num_traits; num_traits++) {
-		trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
+		const zend_class_entry *trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
 			pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT);
 		ZEND_ASSERT(trait);
 		spl_add_class_name(list, trait, allow, ce_flags);
@@ -63,7 +61,7 @@ void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)


 /* {{{ spl_add_classes */
-void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags)
+void spl_add_classes(const zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags)
 {
 	ZEND_ASSERT(pce);
 	spl_add_class_name(list, pce, allow, ce_flags);
diff --git a/ext/spl/spl_functions.h b/ext/spl/spl_functions.h
index eb81a8b8f81..ca92a237169 100644
--- a/ext/spl/spl_functions.h
+++ b/ext/spl/spl_functions.h
@@ -24,10 +24,10 @@
    allow > 0: allow all that match and mask ce_flags
    allow < 0: disallow all that match and mask ce_flags
  */
-void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags);
-void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags);
-void spl_add_traits(zval * list, zend_class_entry * pce, int allow, int ce_flags);
-void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags);
+void spl_add_class_name(zval * list, const zend_class_entry *pce, int allow, int ce_flags);
+void spl_add_interfaces(zval * list, const zend_class_entry *pce, int allow, int ce_flags);
+void spl_add_traits(zval * list, const zend_class_entry *pce, int allow, int ce_flags);
+void spl_add_classes(const zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags);

 void spl_set_private_debug_info_property(const zend_class_entry *ce, const char *property, size_t property_len, HashTable *debug_info, zval *value);

diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c
index afe3489e898..eef25b9e359 100644
--- a/ext/spl/spl_heap.c
+++ b/ext/spl/spl_heap.c
@@ -412,7 +412,7 @@ static void spl_heap_object_free_storage(zend_object *object) /* {{{ */
 static zend_object *spl_heap_object_new_ex(zend_class_entry *class_type, zend_object *orig, int clone_orig) /* {{{ */
 {
 	spl_heap_object   *intern;
-	zend_class_entry  *parent = class_type;
+	const zend_class_entry  *parent = class_type;
 	int                inherited = 0;

 	intern = zend_object_alloc(sizeof(spl_heap_object), parent);
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index 801c091fbb4..68f132069a7 100644
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -257,7 +257,7 @@ static void spl_object_storage_addall(spl_SplObjectStorage *intern, spl_SplObjec
 static zend_object *spl_object_storage_new_ex(zend_class_entry *class_type, zend_object *orig) /* {{{ */
 {
 	spl_SplObjectStorage *intern;
-	zend_class_entry *parent = class_type;
+	const zend_class_entry *parent = class_type;

 	intern = zend_object_alloc(sizeof(spl_SplObjectStorage), parent);
 	intern->pos = 0;