@@ -799,59 +799,24 @@ static inline zend_result ct_eval_array_key_exists(zval *result, zval *op1, zval
799
799
return SUCCESS ;
800
800
}
801
801
802
- static bool can_ct_eval_func_call (zend_string * name , uint32_t num_args , zval * * args ) {
802
+ static bool can_ct_eval_func_call (zend_function * func , zend_string * name , uint32_t num_args , zval * * args ) {
803
+ /* Precondition: func->type == ZEND_INTERNAL_FUNCTION, this is a global function */
803
804
/* Functions in this list must always produce the same result for the same arguments,
804
805
* 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. */
806
- if (false
807
- || zend_string_equals_literal (name , "array_diff" )
808
- || zend_string_equals_literal (name , "array_diff_assoc" )
809
- || zend_string_equals_literal (name , "array_diff_key" )
810
- || zend_string_equals_literal (name , "array_flip" )
811
- || zend_string_equals_literal (name , "array_is_list" )
812
- || zend_string_equals_literal (name , "array_key_exists" )
813
- || zend_string_equals_literal (name , "array_keys" )
814
- || zend_string_equals_literal (name , "array_merge" )
815
- || zend_string_equals_literal (name , "array_merge_recursive" )
816
- || zend_string_equals_literal (name , "array_replace" )
817
- || zend_string_equals_literal (name , "array_replace_recursive" )
818
- || zend_string_equals_literal (name , "array_unique" )
819
- || zend_string_equals_literal (name , "array_values" )
820
- || zend_string_equals_literal (name , "base64_decode" )
821
- || zend_string_equals_literal (name , "base64_encode" )
806
+ * or warn on invalid arguments, as we detect this and will discard the evaluation result.
807
+ *
808
+ * In PHP 8.2, many functions stopped depending on locales due to https://wiki.php.net/rfc/strtolower-ascii */
809
+ zend_internal_function * internal_func = (zend_internal_function * )func ;
810
+ if (internal_func -> fn_flags & ZEND_ACC_COMPILE_TIME_EVAL ) {
811
+ /* This has @compile-time-eval in stub info and uses a macro such as ZEND_SUPPORTS_COMPILE_TIME_EVAL_FE */
812
+ return true;
813
+ }
822
814
#ifndef ZEND_WIN32
823
- /* On Windows this function may be code page dependent. */
824
- || zend_string_equals_literal (name , "dirname" )
825
- #endif
826
- || zend_string_equals_literal (name , "explode" )
827
- || zend_string_equals_literal (name , "imagetypes" )
828
- || zend_string_equals_literal (name , "in_array" )
829
- || zend_string_equals_literal (name , "implode" )
830
- || zend_string_equals_literal (name , "ltrim" )
831
- || zend_string_equals_literal (name , "php_sapi_name" )
832
- || zend_string_equals_literal (name , "php_uname" )
833
- || zend_string_equals_literal (name , "phpversion" )
834
- || zend_string_equals_literal (name , "pow" )
835
- || zend_string_equals_literal (name , "preg_quote" )
836
- || zend_string_equals_literal (name , "rawurldecode" )
837
- || zend_string_equals_literal (name , "rawurlencode" )
838
- || zend_string_equals_literal (name , "rtrim" )
839
- || zend_string_equals_literal (name , "serialize" )
840
- || zend_string_equals_literal (name , "str_contains" )
841
- || zend_string_equals_literal (name , "str_ends_with" )
842
- || zend_string_equals_literal (name , "str_replace" )
843
- || zend_string_equals_literal (name , "str_split" )
844
- || zend_string_equals_literal (name , "str_starts_with" )
845
- || zend_string_equals_literal (name , "strpos" )
846
- || zend_string_equals_literal (name , "strstr" )
847
- || zend_string_equals_literal (name , "substr" )
848
- || zend_string_equals_literal (name , "trim" )
849
- || zend_string_equals_literal (name , "urldecode" )
850
- || zend_string_equals_literal (name , "urlencode" )
851
- || zend_string_equals_literal (name , "version_compare" )
852
- ) {
815
+ /* On Windows this function may be code page dependent. */
816
+ if (zend_string_equals_literal (name , "dirname" )) {
853
817
return true;
854
818
}
819
+ #endif
855
820
856
821
if (num_args == 2 ) {
857
822
if (zend_string_equals_literal (name , "str_repeat" )) {
@@ -918,7 +883,7 @@ static inline zend_result ct_eval_func_call(
918
883
}
919
884
}
920
885
921
- if (!can_ct_eval_func_call (name , num_args , args )) {
886
+ if (!can_ct_eval_func_call (func , name , num_args , args )) {
922
887
return FAILURE ;
923
888
}
924
889
0 commit comments