Skip to content

Commit 2034bc5

Browse files
committed
Use known zend_string instead of C string
1 parent da015c2 commit 2034bc5

21 files changed

+33
-32
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4560,7 +4560,7 @@ ZEND_API zend_class_constant *zend_declare_typed_class_constant(zend_class_entry
45604560
}
45614561
}
45624562

4563-
if (zend_string_equals_literal_ci(name, "class")) {
4563+
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_CLASS))) {
45644564
zend_error_noreturn(ce->type == ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR,
45654565
"A class constant must not be called 'class'; it is reserved for class name fetching");
45664566
}

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_constant(zend_string *name, ze
101101

102102
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_class_const_or_name(zend_ast *class_name, zend_ast *name) {
103103
zend_string *name_str = zend_ast_get_str(name);
104-
if (zend_string_equals_literal_ci(name_str, "class")) {
104+
if (zend_string_equals_ci(name_str, ZSTR_KNOWN(ZEND_STR_CLASS))) {
105105
zend_string_release(name_str);
106106
return zend_ast_create(ZEND_AST_CLASS_NAME, class_name);
107107
} else {

Zend/zend_attributes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ZEND_METHOD(SensitiveParameterValue, __construct)
114114
Z_PARAM_ZVAL(value)
115115
ZEND_PARSE_PARAMETERS_END();
116116

117-
zend_update_property(zend_ce_sensitive_parameter_value, Z_OBJ_P(ZEND_THIS), "value", strlen("value"), value);
117+
zend_update_property_ex(zend_ce_sensitive_parameter_value, Z_OBJ_P(ZEND_THIS), ZSTR_KNOWN(ZEND_STR_VALUE), value);
118118
}
119119

120120
ZEND_METHOD(SensitiveParameterValue, getValue)

Zend/zend_builtin_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ ZEND_FUNCTION(get_defined_functions)
13221322
} ZEND_HASH_FOREACH_END();
13231323

13241324
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
1325-
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
1325+
zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_USER), &user);
13261326
}
13271327
/* }}} */
13281328

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ ZEND_API zend_string *zend_type_to_string(zend_type type) {
14291429
}
14301430

14311431
static bool is_generator_compatible_class_type(zend_string *name) {
1432-
return zend_string_equals_literal_ci(name, "Traversable")
1432+
return zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_TRAVERSABLE))
14331433
|| zend_string_equals_literal_ci(name, "Iterator")
14341434
|| zend_string_equals_literal_ci(name, "Generator");
14351435
}

Zend/zend_enum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ static void zend_verify_enum_properties(zend_class_entry *ce)
6262
zend_property_info *property_info;
6363

6464
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, property_info) {
65-
if (zend_string_equals_literal(property_info->name, "name")) {
65+
if (zend_string_equals(property_info->name, ZSTR_KNOWN(ZEND_STR_NAME))) {
6666
continue;
6767
}
6868
if (
6969
ce->enum_backing_type != IS_UNDEF
70-
&& zend_string_equals_literal(property_info->name, "value")
70+
&& zend_string_equals(property_info->name, ZSTR_KNOWN(ZEND_STR_VALUE))
7171
) {
7272
continue;
7373
}

Zend/zend_interfaces.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry
344344
&class_type->function_table, "rewind", sizeof("rewind") - 1);
345345
funcs_ptr->zf_valid = zend_hash_str_find_ptr(
346346
&class_type->function_table, "valid", sizeof("valid") - 1);
347-
funcs_ptr->zf_key = zend_hash_str_find_ptr(
348-
&class_type->function_table, "key", sizeof("key") - 1);
347+
funcs_ptr->zf_key = zend_hash_find_ptr(
348+
&class_type->function_table, ZSTR_KNOWN(ZEND_STR_KEY));
349349
funcs_ptr->zf_current = zend_hash_str_find_ptr(
350350
&class_type->function_table, "current", sizeof("current") - 1);
351351
funcs_ptr->zf_next = zend_hash_str_find_ptr(

ext/curl/interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
13771377
curl_seek_callback seekfunc = seek_cb;
13781378
#endif
13791379

1380-
prop = zend_read_property(curl_CURLFile_class, Z_OBJ_P(current), "name", sizeof("name")-1, 0, &rv);
1380+
prop = zend_read_property_ex(curl_CURLFile_class, Z_OBJ_P(current), ZSTR_KNOWN(ZEND_STR_NAME), /* silent */ false, &rv);
13811381
ZVAL_DEREF(prop);
13821382
if (Z_TYPE_P(prop) != IS_STRING) {
13831383
php_error_docref(NULL, E_WARNING, "Invalid filename for key %s", ZSTR_VAL(string_key));

ext/dom/node.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,8 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
16221622
zval *tmp;
16231623
char *xquery;
16241624

1625-
tmp = zend_hash_str_find(ht, "query", sizeof("query")-1);
1625+
/* Find "query" key */
1626+
tmp = zend_hash_find(ht, ZSTR_KNOWN(ZEND_STR_QUERY));
16261627
if (!tmp) {
16271628
/* if mode == 0 then $xpath arg is 3, if mode == 1 then $xpath is 4 */
16281629
zend_argument_value_error(3 + mode, "must have a \"query\" key");

ext/ftp/ftp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ ftp_mlsd_parse_line(HashTable *ht, const char *input) {
708708

709709
/* Extract pathname */
710710
ZVAL_STRINGL(&zstr, sp + 1, end - sp - 1);
711-
zend_hash_str_update(ht, "name", sizeof("name")-1, &zstr);
711+
zend_hash_update(ht, ZSTR_KNOWN(ZEND_STR_NAME), &zstr);
712712
end = sp;
713713

714714
while (input < end) {

ext/ldap/ldap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
412412
struct berval control_value = { 0L, NULL };
413413
int control_value_alloc = 0;
414414

415-
if ((val = zend_hash_str_find(Z_ARRVAL_P(array), "value", sizeof("value") - 1)) != NULL) {
415+
if ((val = zend_hash_find(Z_ARRVAL_P(array), ZSTR_KNOWN(ZEND_STR_VALUE))) != NULL) {
416416
if (Z_TYPE_P(val) != IS_ARRAY) {
417417
tmpstring = zval_get_string(val);
418418
if (EG(exception)) {

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4822,7 +4822,7 @@ ZEND_EXT_API int zend_jit_config(zend_string *jit, int stage)
48224822
JIT_G(trigger) = ZEND_JIT_ON_HOT_TRACE;
48234823
JIT_G(opt_flags) = ZEND_JIT_REG_ALLOC_GLOBAL | ZEND_JIT_CPU_AVX;
48244824
return SUCCESS;
4825-
} else if (zend_string_equals_literal_ci(jit, "function")) {
4825+
} else if (zend_string_equals_ci(jit, ZSTR_KNOWN(ZEND_STR_FUNCTION))) {
48264826
JIT_G(enabled) = 1;
48274827
JIT_G(on) = 1;
48284828
JIT_G(opt_level) = ZEND_JIT_LEVEL_OPT_SCRIPT;

ext/opcache/zend_persist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ void zend_update_parent_ce(zend_class_entry *ce)
11211121
if (zend_class_implements_interface(ce, zend_ce_iterator)) {
11221122
ce->iterator_funcs_ptr->zf_rewind = zend_hash_str_find_ptr(&ce->function_table, "rewind", sizeof("rewind") - 1);
11231123
ce->iterator_funcs_ptr->zf_valid = zend_hash_str_find_ptr(&ce->function_table, "valid", sizeof("valid") - 1);
1124-
ce->iterator_funcs_ptr->zf_key = zend_hash_str_find_ptr(&ce->function_table, "key", sizeof("key") - 1);
1124+
ce->iterator_funcs_ptr->zf_key = zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_KEY));
11251125
ce->iterator_funcs_ptr->zf_current = zend_hash_str_find_ptr(&ce->function_table, "current", sizeof("current") - 1);
11261126
ce->iterator_funcs_ptr->zf_next = zend_hash_str_find_ptr(&ce->function_table, "next", sizeof("next") - 1);
11271127
}

ext/reflection/php_reflection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7137,7 +7137,7 @@ ZEND_METHOD(ReflectionFiber, getCallable)
71377137
static zval *_reflection_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
71387138
{
71397139
if (zend_hash_exists(&object->ce->properties_info, name)
7140-
&& (zend_string_equals_literal(name, "name") || zend_string_equals_literal(name, "class")))
7140+
&& (zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_NAME)) || zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_CLASS))))
71417141
{
71427142
zend_throw_exception_ex(reflection_exception_ptr, 0,
71437143
"Cannot set read-only property %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(name));

ext/session/session.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ PHP_FUNCTION(session_module_name)
19271927
}
19281928

19291929
if (name) {
1930-
if (zend_string_equals_literal_ci(name, "user")) {
1930+
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_USER))) {
19311931
zend_argument_value_error(1, "cannot be \"user\"");
19321932
RETURN_THROWS();
19331933
}
@@ -1967,7 +1967,7 @@ static inline void set_user_save_handler_ini(void) {
19671967
zend_string *ini_name, *ini_val;
19681968

19691969
ini_name = ZSTR_INIT_LITERAL("session.save_handler", 0);
1970-
ini_val = ZSTR_INIT_LITERAL("user", 0);
1970+
ini_val = ZSTR_KNOWN(ZEND_STR_USER);
19711971
PS(set_handler) = 1;
19721972
zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
19731973
PS(set_handler) = 0;

ext/soap/soap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ PHP_METHOD(SoapFault, __toString)
584584
this_ptr = ZEND_THIS;
585585
faultcode = zend_read_property(soap_fault_class_entry, Z_OBJ_P(this_ptr), "faultcode", sizeof("faultcode")-1, 1, &rv1);
586586
faultstring = zend_read_property(soap_fault_class_entry, Z_OBJ_P(this_ptr), "faultstring", sizeof("faultstring")-1, 1, &rv2);
587-
file = zend_read_property_ex(soap_fault_class_entry, Z_OBJ_P(this_ptr) ZSTR_KNOWN(ZEND_STR_FILE), /* silent */ true, &rv));
588-
line = zend_read_property_ex(soap_fault_class_entry, Z_OBJ_P(this_ptr), ZSTR_KNOWN(ZEND_STR_LINE), /* silent */ true, &rv));
587+
file = zend_read_property_ex(soap_fault_class_entry, Z_OBJ_P(this_ptr), ZSTR_KNOWN(ZEND_STR_FILE), /* silent */ true, &rv3);
588+
line = zend_read_property_ex(soap_fault_class_entry, Z_OBJ_P(this_ptr), ZSTR_KNOWN(ZEND_STR_LINE), /* silent */ true, &rv4);
589589

590590
zend_call_method_with_0_params(
591591
Z_OBJ_P(ZEND_THIS), Z_OBJCE_P(ZEND_THIS), NULL, "gettraceasstring", &trace);
@@ -1943,7 +1943,7 @@ PHP_METHOD(SoapClient, __construct)
19431943
php_stream_context_set_option(context, "ssl", "passphrase", tmp);
19441944
}
19451945
}
1946-
if ((tmp = zend_hash_str_find(ht, "trace", sizeof("trace")-1)) != NULL &&
1946+
if ((tmp = zend_hash_find(ht, ZSTR_KNOWN(ZEND_STR_TRACE))) != NULL &&
19471947
(Z_TYPE_P(tmp) == IS_TRUE ||
19481948
(Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == 1))) {
19491949
ZVAL_TRUE(Z_CLIENT_TRACE_P(this_ptr));

ext/sodium/libsodium.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ ZEND_GET_MODULE(sodium)
125125
/* Remove argument information from backtrace to prevent information leaks */
126126
static void sodium_remove_param_values_from_backtrace(zend_object *obj) {
127127
zval rv;
128-
zval *trace = zend_read_property(zend_get_exception_base(obj), obj, "trace", sizeof("trace")-1, 0, &rv);
128+
zval *trace = zend_read_property_ex(zend_get_exception_base(obj), obj, ZSTR_KNOWN(ZEND_STR_TRACE), /* silent */ false, &rv);
129129
if (trace && Z_TYPE_P(trace) == IS_ARRAY) {
130130
zval *frame;
131131
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(trace), frame) {
132132
if (Z_TYPE_P(frame) == IS_ARRAY) {
133-
zval *args = zend_hash_str_find(Z_ARRVAL_P(frame), "args", sizeof("args")-1);
133+
zval *args = zend_hash_find(Z_ARRVAL_P(frame), ZSTR_KNOWN(ZEND_STR_ARGS));
134134
if (args) {
135135
zval_ptr_dtor(args);
136136
ZVAL_EMPTY_ARRAY(args);

ext/xml/xml.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
762762
if (parser->lastwasopen) {
763763
zval *myval;
764764
/* check if the current tag already has a value - if yes append to that! */
765-
if ((myval = zend_hash_str_find(Z_ARRVAL_P(parser->ctag), "value", sizeof("value") - 1))) {
765+
if ((myval = zend_hash_find(Z_ARRVAL_P(parser->ctag), ZSTR_KNOWN(ZEND_STR_VALUE)))) {
766766
size_t newlen = Z_STRLEN_P(myval) + ZSTR_LEN(decoded_value);
767767
Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
768768
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - ZSTR_LEN(decoded_value),
@@ -781,7 +781,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
781781
ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL(parser->data), curtag) {
782782
if ((mytype = zend_hash_str_find(Z_ARRVAL_P(curtag),"type", sizeof("type") - 1))) {
783783
if (zend_string_equals_literal(Z_STR_P(mytype), "cdata")) {
784-
if ((myval = zend_hash_str_find(Z_ARRVAL_P(curtag), "value", sizeof("value") - 1))) {
784+
if ((myval = zend_hash_find(Z_ARRVAL_P(curtag), ZSTR_KNOWN(ZEND_STR_VALUE)))) {
785785
size_t newlen = Z_STRLEN_P(myval) + ZSTR_LEN(decoded_value);
786786
Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
787787
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - ZSTR_LEN(decoded_value),

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static PHP_INI_MH(OnSetFacility)
169169
}
170170
#endif
171171
#ifdef LOG_USER
172-
if (zend_string_equals_literal(facility, "LOG_USER") || zend_string_equals_literal(facility, "user")) {
172+
if (zend_string_equals(facility, ZSTR_KNOWN(ZEND_STR_USER)) || zend_string_equals_literal(facility, "LOG_USER")) {
173173
PG(syslog_facility) = LOG_USER;
174174
return SUCCESS;
175175
}

sapi/cli/php_cli_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static void append_essential_headers(smart_str* buffer, php_cli_server_client *c
361361
zval *val;
362362
struct timeval tv = {0};
363363

364-
if (NULL != (val = zend_hash_str_find(&client->request.headers, "host", sizeof("host")-1))) {
364+
if (NULL != (val = zend_hash_find(&client->request.headers, ZSTR_KNOWN(ZEND_STR_HOST)))) {
365365
smart_str_appends_ex(buffer, "Host: ", persistent);
366366
smart_str_append_ex(buffer, Z_STR_P(val), persistent);
367367
smart_str_appends_ex(buffer, "\r\n", persistent);

sapi/phpdbg/phpdbg_frame.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,24 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
171171
{
172172
zval *funcname, *class, class_zv, *args, *argstmp;
173173

174-
funcname = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("function"));
174+
funcname = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_FUNCTION));
175175

176-
if ((class = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("object")))) {
176+
if ((class = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_OBJECT)))) {
177177
ZVAL_NEW_STR(&class_zv, Z_OBJCE_P(class)->name);
178178
class = &class_zv;
179179
} else {
180-
class = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("class"));
180+
class = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_CLASS));
181181
}
182182

183183
if (class) {
184-
zval *type = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("type"));
184+
zval *type = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_TYPE));
185185

186186
phpdbg_out("%s%s%s(", Z_STRVAL_P(class), Z_STRVAL_P(type), Z_STRVAL_P(funcname));
187187
} else {
188188
phpdbg_out("%s(", Z_STRVAL_P(funcname));
189189
}
190190

191-
args = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("args"));
191+
args = zend_hash_find(Z_ARRVAL_P(tmp), ZSTR_KNOWN(ZEND_STR_ARGS));
192192

193193
if (args) {
194194
const zend_function *func = NULL;

0 commit comments

Comments
 (0)