Commit b2ada37d65b for php

commit b2ada37d65b087c9ac6a65eeb3b9fcfd2f0bde86
Author: Alexander Danilov <10532067+adapik@users.noreply.github.com>
Date:   Fri Nov 27 12:28:55 2026 +0200

    tree: use zend_hash_num_elements() and HT_IS_WITHOUT_HOLES() instead of direct member access (#25797)

diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index 87779dabd09..d04af40bffe 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -283,7 +283,7 @@ static zend_result do_closure_bind(zval *return_value, zval *zclosure, zend_obje

 		zend_closure *new_closure = (zend_closure*)Z_OBJ_P(return_value);
 		HashTable *static_variables = ZEND_MAP_PTR_GET(new_closure->func.op_array.static_variables_ptr);
-		ZEND_ASSERT(static_variables->nNumOfElements > 0);
+		ZEND_ASSERT(zend_hash_num_elements(static_variables) > 0);
 		zval *inner = &static_variables->arData[0].val;
 		ZEND_ASSERT(Z_TYPE_P(inner) == IS_OBJECT && Z_OBJCE_P(inner) == zend_ce_closure);

diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c
index c72163d75a4..5cbf94aebc2 100644
--- a/Zend/zend_ini.c
+++ b/Zend/zend_ini.c
@@ -166,7 +166,7 @@ ZEND_API void zend_copy_ini_directives(void) /* {{{ */
 	EG(modified_ini_directives) = NULL;
 	EG(error_reporting_ini_entry) = NULL;
 	EG(ini_directives) = (HashTable *) malloc(sizeof(HashTable));
-	zend_hash_init(EG(ini_directives), registered_zend_ini_directives->nNumOfElements, NULL, free_ini_entry, true);
+	zend_hash_init(EG(ini_directives), zend_hash_num_elements(registered_zend_ini_directives), NULL, free_ini_entry, true);
 	zend_hash_copy(EG(ini_directives), registered_zend_ini_directives, copy_ini_entry);
 }
 /* }}} */
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index 8e828746964..ef53d76309a 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -643,11 +643,11 @@ uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_s
 	new_persistent_script->size = (new_persistent_script->size + 63) & ~63;
 #endif

-	if (new_persistent_script->script.class_table.nNumUsed != new_persistent_script->script.class_table.nNumOfElements) {
+	if (!HT_IS_WITHOUT_HOLES(&new_persistent_script->script.class_table)) {
 		zend_hash_rehash(&new_persistent_script->script.class_table);
 	}
 	zend_accel_persist_class_table_calc(&new_persistent_script->script.class_table);
-	if (new_persistent_script->script.function_table.nNumUsed != new_persistent_script->script.function_table.nNumOfElements) {
+	if (!HT_IS_WITHOUT_HOLES(&new_persistent_script->script.function_table)) {
 		zend_hash_rehash(&new_persistent_script->script.function_table);
 	}
 	zend_hash_persist_calc(&new_persistent_script->script.function_table);
diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c
index 672cebe7bed..b6de453be41 100644
--- a/ext/phar/dirstream.c
+++ b/ext/phar/dirstream.c
@@ -154,7 +154,7 @@ static php_stream *phar_make_dirstream(const char *dir, size_t dirlen, const Has
 	ALLOC_HASHTABLE(data);
 	zend_hash_init(data, 64, NULL, NULL, 0);

-	if ((*dir == '/' && dirlen == 1 && (manifest->nNumOfElements == 0)) || phar_path_is_magic_phar_ex(dir, dirlen)) {
+	if ((*dir == '/' && dirlen == 1 && (zend_hash_num_elements(manifest) == 0)) || phar_path_is_magic_phar_ex(dir, dirlen)) {
 		/* make empty root directory for empty phar */
 		/* make empty directory for .phar magic directory */
 		return php_stream_alloc(&phar_dir_ops, data, NULL, "r");
diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c
index 69ab56169c4..3aa31f47428 100644
--- a/ext/soap/php_sdl.c
+++ b/ext/soap/php_sdl.c
@@ -1300,7 +1300,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri)
 			zend_hash_move_forward(&ctx.services);
 		}

-		if (ctx.sdl->bindings == NULL || ctx.sdl->bindings->nNumOfElements == 0) {
+		if (ctx.sdl->bindings == NULL || zend_hash_num_elements(ctx.sdl->bindings) == 0) {
 			soap_error0(E_ERROR, "Parsing WSDL: Could not find any usable binding services in WSDL.");
 		}

diff --git a/ext/standard/array.c b/ext/standard/array.c
index 55504cb06c6..11fd3f0e29a 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -3199,7 +3199,7 @@ PHPAPI bool php_array_data_shuffle(php_random_algo_with_state engine, zval *arra
 	}

 	if (EXPECTED(!HT_HAS_ITERATORS(hash))) {
-		if (hash->nNumUsed != hash->nNumOfElements) {
+		if (!HT_IS_WITHOUT_HOLES(hash)) {
 			for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
 				zv = hash->arPacked + idx;
 				if (Z_TYPE_P(zv) == IS_UNDEF) continue;
@@ -3227,7 +3227,7 @@ PHPAPI bool php_array_data_shuffle(php_random_algo_with_state engine, zval *arra
 	} else {
 		zend_long iter_pos = zend_hash_iterators_lower_pos(hash, 0);

-		if (hash->nNumUsed != hash->nNumOfElements) {
+		if (!HT_IS_WITHOUT_HOLES(hash)) {
 			for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
 				zv = hash->arPacked + idx;
 				if (Z_TYPE_P(zv) == IS_UNDEF) continue;
@@ -3853,7 +3853,7 @@ static inline Bucket* find_bucket_at_offset(HashTable* ht, zend_long offset)
 {
 	zend_long pos;
 	Bucket *bucket;
-	ZEND_ASSERT(offset >= 0 && offset <= ht->nNumOfElements);
+	ZEND_ASSERT(offset >= 0 && offset <= zend_hash_num_elements(ht));
 	if (HT_IS_WITHOUT_HOLES(ht)) {
 		/* There's no need to iterate over the array to filter out holes if there are no holes */
 		return ht->arData + offset;
@@ -3879,7 +3879,7 @@ static inline zval* find_packed_val_at_offset(HashTable* ht, zend_long offset)
 {
 	zend_long pos;
 	zval *zv;
-	ZEND_ASSERT(offset >= 0 && offset <= ht->nNumOfElements);
+	ZEND_ASSERT(offset >= 0 && offset <= zend_hash_num_elements(ht));
 	if (HT_IS_WITHOUT_HOLES(ht)) {
 		/* There's no need to iterate over the array to filter out holes if there are no holes */
 		return ht->arPacked + offset;
@@ -5029,7 +5029,7 @@ PHP_FUNCTION(array_unique)
 		Z_PARAM_LONG(sort_type)
 	ZEND_PARSE_PARAMETERS_END();

-	if (Z_ARRVAL_P(array)->nNumOfElements <= 1) {	/* nothing to do */
+	if (zend_hash_num_elements(Z_ARRVAL_P(array)) <= 1) {	/* nothing to do */
 		ZVAL_COPY(return_value, array);
 		return;
 	}
@@ -5083,7 +5083,7 @@ PHP_FUNCTION(array_unique)
 	}

 	/* create and sort array with pointers to the target_hash buckets */
-	arTmp = pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex), GC_FLAGS(Z_ARRVAL_P(array)) & IS_ARRAY_PERSISTENT);
+	arTmp = pemalloc((zend_hash_num_elements(Z_ARRVAL_P(array)) + 1) * sizeof(struct bucketindex), GC_FLAGS(Z_ARRVAL_P(array)) & IS_ARRAY_PERSISTENT);
 	if (HT_IS_PACKED(Z_ARRVAL_P(array))) {
 		zval *zv = Z_ARRVAL_P(array)->arPacked;
 		for (i = 0, idx = 0; idx < Z_ARRVAL_P(array)->nNumUsed; idx++, zv++) {
@@ -5352,7 +5352,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
 			goto out;
 		}
 		hash = Z_ARRVAL(args[i]);
-		list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), GC_FLAGS(hash) & IS_ARRAY_PERSISTENT);
+		list = (Bucket *) pemalloc((zend_hash_num_elements(hash) + 1) * sizeof(Bucket), GC_FLAGS(hash) & IS_ARRAY_PERSISTENT);
 		lists[i] = list;
 		ptrs[i] = list;
 		if (HT_IS_PACKED(hash)) {
@@ -5372,13 +5372,13 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
 			}
 		}
 		ZVAL_UNDEF(&list->val);
-		if (hash->nNumOfElements > 1) {
+		if (zend_hash_num_elements(hash) > 1) {
 			if (behavior == INTERSECT_NORMAL) {
-				zend_sort((void *) lists[i], hash->nNumOfElements,
+				zend_sort((void *) lists[i], zend_hash_num_elements(hash),
 						sizeof(Bucket), (compare_func_t) intersect_data_compare_func,
 						(swap_func_t)zend_hash_bucket_swap);
 			} else if (behavior & INTERSECT_ASSOC) { /* triggered also when INTERSECT_KEY */
-				zend_sort((void *) lists[i], hash->nNumOfElements,
+				zend_sort((void *) lists[i], zend_hash_num_elements(hash),
 						sizeof(Bucket), (compare_func_t) intersect_key_compare_func,
 						(swap_func_t)zend_hash_bucket_swap);
 			}
@@ -5956,7 +5956,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
 			goto out;
 		}
 		hash = Z_ARRVAL(args[i]);
-		list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), GC_FLAGS(hash) & IS_ARRAY_PERSISTENT);
+		list = (Bucket *) pemalloc((zend_hash_num_elements(hash) + 1) * sizeof(Bucket), GC_FLAGS(hash) & IS_ARRAY_PERSISTENT);
 		lists[i] = list;
 		ptrs[i] = list;
 		if (HT_IS_PACKED(hash)) {
@@ -5976,13 +5976,13 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
 			}
 		}
 		ZVAL_UNDEF(&list->val);
-		if (hash->nNumOfElements > 1) {
+		if (zend_hash_num_elements(hash) > 1) {
 			if (behavior == DIFF_NORMAL) {
-				zend_sort((void *) lists[i], hash->nNumOfElements,
+				zend_sort((void *) lists[i], zend_hash_num_elements(hash),
 						sizeof(Bucket), (compare_func_t) diff_data_compare_func,
 						(swap_func_t)zend_hash_bucket_swap);
 			} else if (behavior & DIFF_ASSOC) { /* triggered also when DIFF_KEY */
-				zend_sort((void *) lists[i], hash->nNumOfElements,
+				zend_sort((void *) lists[i], zend_hash_num_elements(hash),
 						sizeof(Bucket), (compare_func_t) diff_key_compare_func,
 						(swap_func_t)zend_hash_bucket_swap);
 			}