Commit 8908a819730 for php.net

commit 8908a81973076967c53f0818b893dd18295ebffc
Author: Niels Dossche <7771979+ndossche@users.noreply.github.com>
Date:   Mon Dec 8 13:28:03 2025 -0800

    ldap: Use cheaper checks for getting a string (#20652)

    Avoids loading globals, the return register can be used directly.

diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index e9acd189906..c2b08d0c670 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -425,7 +425,7 @@ static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array,
 static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashTable *control_ht)
 {
 	zval* val;
-	zend_string *control_oid;
+	zend_string *control_oid, *control_oid_tmp;
 	char** ldap_attrs = NULL;
 	LDAPSortKey** sort_keys = NULL;
 	zend_string *tmpstring = NULL, **tmpstrings1 = NULL, **tmpstrings2 = NULL;
@@ -436,8 +436,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 		return -1;
 	}

-	control_oid = zval_get_string(val);
-	if (EG(exception)) {
+	control_oid = zval_try_get_tmp_string(val, &control_oid_tmp);
+	if (!control_oid) {
 		return -1;
 	}

@@ -453,8 +453,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT

 	if ((val = zend_hash_find(control_ht, ZSTR_KNOWN(ZEND_STR_VALUE))) != NULL) {
 		if (Z_TYPE_P(val) != IS_ARRAY) {
-			tmpstring = zval_get_string(val);
-			if (EG(exception)) {
+			tmpstring = zval_try_get_string(val);
+			if (!tmpstring) {
 				rc = -1;
 				goto failure;
 			}
@@ -468,8 +468,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 				pagesize = zval_get_long(tmp);
 			}
 			if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "cookie", sizeof("cookie") - 1)) != NULL) {
-				tmpstring = zval_get_string(tmp);
-				if (EG(exception)) {
+				tmpstring = zval_try_get_string(tmp);
+				if (!tmpstring) {
 					rc = -1;
 					goto failure;
 				}
@@ -488,8 +488,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 				rc = -1;
 				zend_value_error("%s(): Control must have a \"filter\" key", get_active_function_name());
 			} else {
-				zend_string* assert = zval_get_string(tmp);
-				if (EG(exception)) {
+				zend_string* assert = zval_try_get_string(tmp);
+				if (!assert) {
 					rc = -1;
 					goto failure;
 				}
@@ -516,8 +516,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 					rc = -1;
 					php_error_docref(NULL, E_WARNING, "Failed to allocate control value");
 				} else {
-					tmpstring = zval_get_string(tmp);
-					if (EG(exception)) {
+					tmpstring = zval_try_get_string(tmp);
+					if (!tmpstring) {
 						rc = -1;
 						goto failure;
 					}
@@ -555,8 +555,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 							goto failure;
 						}

-						tmpstrings1[num_tmpstrings1] = zval_get_string(attr);
-						if (EG(exception)) {
+						tmpstrings1[num_tmpstrings1] = zval_try_get_string(attr);
+						if (!tmpstrings1[num_tmpstrings1]) {
 							rc = -1;
 							goto failure;
 						}
@@ -603,8 +603,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 					goto failure;
 				}
 				sort_keys[i] = emalloc(sizeof(LDAPSortKey));
-				tmpstrings1[num_tmpstrings1] = zval_get_string(tmp);
-				if (EG(exception)) {
+				tmpstrings1[num_tmpstrings1] = zval_try_get_string(tmp);
+				if (!tmpstrings1[num_tmpstrings1]) {
 					rc = -1;
 					goto failure;
 				}
@@ -612,8 +612,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 				++num_tmpstrings1;

 				if ((tmp = zend_hash_str_find(Z_ARRVAL_P(sortkey), "oid", sizeof("oid") - 1)) != NULL) {
-					tmpstrings2[num_tmpstrings2] = zval_get_string(tmp);
-					if (EG(exception)) {
+					tmpstrings2[num_tmpstrings2] = zval_try_get_string(tmp);
+					if (!tmpstrings2[num_tmpstrings2]) {
 						rc = -1;
 						goto failure;
 					}
@@ -659,8 +659,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 			}

 			if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "attrvalue", sizeof("attrvalue") - 1)) != NULL) {
-				tmpstring = zval_get_string(tmp);
-				if (EG(exception)) {
+				tmpstring = zval_try_get_string(tmp);
+				if (!tmpstring) {
 					rc = -1;
 					goto failure;
 				}
@@ -685,8 +685,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 			}

 			if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "context", sizeof("context") - 1)) != NULL) {
-				tmpstring = zval_get_string(tmp);
-				if (EG(exception)) {
+				tmpstring = zval_try_get_string(tmp);
+				if (!tmpstring) {
 					rc = -1;
 					goto failure;
 				}
@@ -714,7 +714,7 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
 	}

 failure:
-	zend_string_release(control_oid);
+	zend_tmp_string_release(control_oid_tmp);
 	if (tmpstring != NULL) {
 		zend_string_release(tmpstring);
 	}
@@ -2791,8 +2791,8 @@ PHP_FUNCTION(ldap_modify_batch)
 			zend_ulong value_index = 0;
 			zval *modification_value_zv = NULL;
 			ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(modification_values), modification_value_zv) {
-				zend_string *modval = zval_get_string(modification_value_zv);
-				if (EG(exception)) {
+				zend_string *modval = zval_try_get_string(modification_value_zv);
+				if (!modval) {
 					RETVAL_FALSE;
 					ldap_mods[modification_index]->mod_bvalues[value_index] = NULL;
 					num_mods = modification_index + 1;