Skip to content

Commit aa15d11

Browse files
committed
Do compile-time evaluation of locale-independent case conversion
https://wiki.php.net/rfc/strtolower-ascii means that these functions no longer depend on the current locale in php 8.2. Before that, this was unsafe to evaluate at compile time. Followup to phpGH-7506
1 parent 8eee0d6 commit aa15d11

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Zend/Optimizer/sccp.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,10 @@ static inline zend_result ct_eval_array_key_exists(zval *result, zval *op1, zval
802802
static bool can_ct_eval_func_call(zend_string *name, uint32_t num_args, zval **args) {
803803
/* Functions in this list must always produce the same result for the same arguments,
804804
* and have no dependence on global state (such as locales). It is okay if they throw
805-
* or warn on invalid arguments, as we detect this and will discard the evaluation result. */
805+
* or warn on invalid arguments, as we detect this and will discard the evaluation result.
806+
* In PHP 8.2, many functions stopped depending on locales due to https://wiki.php.net/rfc/strtolower-ascii */
806807
if (false
808+
|| zend_string_equals_literal(name, "array_change_key_case")
807809
|| zend_string_equals_literal(name, "array_diff")
808810
|| zend_string_equals_literal(name, "array_diff_assoc")
809811
|| zend_string_equals_literal(name, "array_diff_key")
@@ -824,6 +826,7 @@ static bool can_ct_eval_func_call(zend_string *name, uint32_t num_args, zval **a
824826
|| zend_string_equals_literal(name, "dirname")
825827
#endif
826828
|| zend_string_equals_literal(name, "explode")
829+
|| zend_string_equals_literal(name, "lcfirst")
827830
|| zend_string_equals_literal(name, "imagetypes")
828831
|| zend_string_equals_literal(name, "in_array")
829832
|| zend_string_equals_literal(name, "implode")
@@ -839,13 +842,21 @@ static bool can_ct_eval_func_call(zend_string *name, uint32_t num_args, zval **a
839842
|| zend_string_equals_literal(name, "serialize")
840843
|| zend_string_equals_literal(name, "str_contains")
841844
|| zend_string_equals_literal(name, "str_ends_with")
845+
|| zend_string_equals_literal(name, "stripos")
846+
|| zend_string_equals_literal(name, "str_ireplace")
847+
|| zend_string_equals_literal(name, "stristr")
842848
|| zend_string_equals_literal(name, "str_replace")
843849
|| zend_string_equals_literal(name, "str_split")
844850
|| zend_string_equals_literal(name, "str_starts_with")
851+
|| zend_string_equals_literal(name, "strtolower")
852+
|| zend_string_equals_literal(name, "strtoupper")
845853
|| zend_string_equals_literal(name, "strpos")
846854
|| zend_string_equals_literal(name, "strstr")
847855
|| zend_string_equals_literal(name, "substr")
848856
|| zend_string_equals_literal(name, "trim")
857+
|| zend_string_equals_literal(name, "ucfirst")
858+
|| zend_string_equals_literal(name, "ucfirst")
859+
|| zend_string_equals_literal(name, "ucwords")
849860
|| zend_string_equals_literal(name, "urldecode")
850861
|| zend_string_equals_literal(name, "urlencode")
851862
|| zend_string_equals_literal(name, "version_compare")

0 commit comments

Comments
 (0)