[php-src] master: Merge branch 'PHP-8.5'

Côme Chilliet <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Côme Chilliet
Pusher: MCMic
Date: 2026-07-13T08:41:25+02:00

Commit: https://github.com/php/php-src/commit/1d82cbde00998709f0197ef6d87c30d638ba1ab6
Raw diff: https://github.com/php/php-src/commit/1d82cbde00998709f0197ef6d87c30d638ba1ab6.diff

Merge branch 'PHP-8.5'

* PHP-8.5:
  ext/ldap: fix ldap_explode_dn result ordering

Changed paths:
  M  ext/ldap/ldap.c
  M  ext/ldap/tests/ldap_explode_dn.phpt


Diff:

diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 9befe134cded..7a089625aa48 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -2202,6 +2202,8 @@ PHP_FUNCTION(ldap_explode_dn)
 	zend_long with_attrib;
 	char *dn, **ldap_value;
 	size_t dn_len;
+	int i, count;
+
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "pl", &dn, &dn_len, &with_attrib) != SUCCESS) {
 		RETURN_THROWS();
@@ -2213,11 +2215,15 @@ PHP_FUNCTION(ldap_explode_dn)
 	}
 
 	array_init(return_value);
-	int i;
-	for (i = 0; ldap_value[i] != NULL; i++) {
+	i = 0;
+	while (ldap_value[i] != NULL) i++;
+	count = i;
+
+	add_assoc_long(return_value, "count", count);
+
+	for (i = 0; i < count; i++) {
 		add_index_string(return_value, i, ldap_value[i]);
 	}
-	add_assoc_long(return_value, "count", i);
 
 	ldap_memvfree((void **)ldap_value);
 }
diff --git a/ext/ldap/tests/ldap_explode_dn.phpt b/ext/ldap/tests/ldap_explode_dn.phpt
index 047078c7beb7..2012506c3ef0 100644
--- a/ext/ldap/tests/ldap_explode_dn.phpt
+++ b/ext/ldap/tests/ldap_explode_dn.phpt
@@ -34,16 +34,18 @@ echo "Done\n";
 ?>
 --EXPECT--
 array(4) {
+  ["count"]=>
+  int(3)
   [0]=>
   string(6) "cn=bob"
   [1]=>
   string(10) "dc=example"
   [2]=>
   string(6) "dc=com"
-  ["count"]=>
-  int(3)
 }
 array(5) {
+  ["count"]=>
+  int(4)
   [0]=>
   string(6) "cn=bob"
   [1]=>
@@ -52,20 +54,20 @@ array(5) {
   string(10) "dc=example"
   [3]=>
   string(6) "dc=com"
-  ["count"]=>
-  int(4)
 }
 array(4) {
+  ["count"]=>
+  int(3)
   [0]=>
   string(3) "bob"
   [1]=>
   string(7) "example"
   [2]=>
   string(3) "com"
-  ["count"]=>
-  int(3)
 }
 array(5) {
+  ["count"]=>
+  int(4)
   [0]=>
   string(3) "bob"
   [1]=>
@@ -74,8 +76,6 @@ array(5) {
   string(7) "example"
   [3]=>
   string(3) "com"
-  ["count"]=>
-  int(4)
 }
 bool(false)
 bool(false)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.