Commit 9ae23bae5f7 for php.net
commit 9ae23bae5f7d20412bac0369c2e72ecc48a9103d
Author: Weilin Du <weilindu@php.net>
Date: Thu Jun 25 17:07:23 2026 +0800
Zend: Use `zend_string_equals*` APIs for string comparisons (#21707)
Use the zend_string APIs zend_string_equals* which are clearer,
and can also do some pointer comparisons if the strings are
interned for any reason.
diff --git a/ext/openssl/openssl_pwhash.c b/ext/openssl/openssl_pwhash.c
index 0b439a731d1..01f7f012413 100644
--- a/ext/openssl/openssl_pwhash.c
+++ b/ext/openssl/openssl_pwhash.c
@@ -329,7 +329,7 @@ PHP_FUNCTION(openssl_password_hash)
Z_PARAM_ARRAY_HT(options)
ZEND_PARSE_PARAMETERS_END();
- if (strcmp(ZSTR_VAL(algo), "argon2i") && strcmp(ZSTR_VAL(algo), "argon2id")) {
+ if (!zend_string_equals_literal(algo, "argon2i") && !zend_string_equals_literal(algo, "argon2id")) {
zend_argument_value_error(1, "must be a valid password openssl hashing algorithm");
RETURN_THROWS();
}
@@ -355,7 +355,7 @@ PHP_FUNCTION(openssl_password_verify)
Z_PARAM_STR(digest)
ZEND_PARSE_PARAMETERS_END();
- if (strcmp(ZSTR_VAL(algo), "argon2i") && strcmp(ZSTR_VAL(algo), "argon2id")) {
+ if (!zend_string_equals_literal(algo, "argon2i") && !zend_string_equals_literal(algo, "argon2id")) {
zend_argument_value_error(1, "must be a valid password openssl hashing algorithm");
RETURN_THROWS();
}
diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c
index 151fa811b0f..f02a1663802 100644
--- a/ext/soap/php_encoding.c
+++ b/ext/soap/php_encoding.c
@@ -253,11 +253,12 @@ static encodePtr find_encoder_by_type_name(sdlPtr sdl, const char *type)
{
if (sdl && sdl->encoders) {
encodePtr enc;
+ size_t type_len = strlen(type);
ZEND_HASH_FOREACH_PTR(sdl->encoders, enc) {
if (type[0] == '{') {
if (enc->details.clark_notation
- && strcmp(ZSTR_VAL(enc->details.clark_notation), type) == 0) {
+ && zend_string_equals_cstr(enc->details.clark_notation, type, type_len)) {
return enc;
}
} else {
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c
index 1f0aa6723c7..2594be75fe1 100644
--- a/ext/soap/php_http.c
+++ b/ext/soap/php_http.c
@@ -325,7 +325,7 @@ static bool in_domain(const zend_string *host, const zend_string *domain)
{
if (ZSTR_VAL(domain)[0] == '.') {
if (ZSTR_LEN(host) > ZSTR_LEN(domain)) {
- return strcmp(ZSTR_VAL(host)+ZSTR_LEN(host)-ZSTR_LEN(domain), ZSTR_VAL(domain)) == 0;
+ return zend_string_equals_cstr(domain, ZSTR_VAL(host) + ZSTR_LEN(host) - ZSTR_LEN(domain), ZSTR_LEN(domain));
} else {
return false;
}