[php-src] master: ext/standard: Allow compile-time evaluation of more standard string functions (#23913)
| From: | Weilin Du via GitHub | Date: | Sun, 27 Sep 2026 16:20:59 +0000 |
| Subject: | [php-src] master: ext/standard: Allow compile-time evaluation of more standard string functions (#23913) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141597@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Committer: GitHub (web-flow)
Pusher: LamentXU123
Date: 2026-09-28T00:20:56+08:00
Commit: https://github.com/php/php-src/commit/d650f5a68b0a9b258bd713d67c5fb3ce63c04912
Raw diff: https://github.com/php/php-src/commit/d650f5a68b0a9b258bd713d67c5fb3ce63c04912.diff
ext/standard: Allow compile-time evaluation of more standard string functions (#23913)
Add it for str_increment() and str_decrement()
as they perform deterministic ASCII string operations
Changed paths:
A ext/opcache/tests/opt/ct_eval_standard_functions.phpt
M ext/standard/basic_functions.stub.php
M ext/standard/basic_functions_arginfo.h
M ext/standard/basic_functions_decl.h
Diff:
diff --git a/ext/opcache/tests/opt/ct_eval_standard_functions.phpt
b/ext/opcache/tests/opt/ct_eval_standard_functions.phpt
new file mode 100644
index 000000000000..f4abd93db520
--- /dev/null
+++ b/ext/opcache/tests/opt/ct_eval_standard_functions.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Compile-time evaluation of str_increment() and str_decrement()
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.opt_debug_level=0x20000
+zend_test.observer.enabled=0
+--FILE--
+<?php
+function test() {
+ return [
+ str_increment('Z9'),
+ str_decrement('AA0'),
+ ];
+}
+var_dump(test());
+?>
+--EXPECTF--
+$_main:
+ ; (lines=6, args=0, vars=0, tmps=1)
+ ; (after optimizer)
+ ; %sct_eval_standard_functions.php:1-10
+0000 INIT_FCALL 1 %d string("var_dump")
+0001 INIT_FCALL 0 %d string("test")
+0002 T0 = DO_UCALL
+0003 SEND_VAL T0 1
+0004 DO_ICALL
+0005 RETURN int(1)
+
+test:
+ ; (lines=1, args=0, vars=0, tmps=0)
+ ; (after optimizer)
+ ; %sct_eval_standard_functions.php:2-7
+0000 RETURN array(...)
+array(2) {
+ [0]=>
+ string(3) "AA0"
+ [1]=>
+ string(2) "Z9"
+}
diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php
index 4b455ec331b6..8d4d8bd9e8b5 100644
--- a/ext/standard/basic_functions.stub.php
+++ b/ext/standard/basic_functions.stub.php
@@ -2388,8 +2388,10 @@ function strtoupper(string $string): string {}
*/
function strtolower(string $string): string {}
+/** @compile-time-eval */
function str_increment(string $string): string {}
+/** @compile-time-eval */
function str_decrement(string $string): string {}
/** @refcount 1 */
diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h
index b770a1e8684c..b0eb39090e00 100644
--- a/ext/standard/basic_functions_arginfo.h
+++ b/ext/standard/basic_functions_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit basic_functions.stub.php instead.
- * Stub hash: b67e9418e158d5726b6a54d446b816264c747116
+ * Stub hash: 9e08e1c2517576dbce825322fe93cbce3054f23e
* Has decl header: yes */
#include "zend_attributes.h"
@@ -3208,8 +3208,8 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(strtok, arginfo_strtok)
ZEND_RAW_FENTRY("strtoupper", zif_strtoupper, arginfo_strtoupper,
ZEND_ACC_COMPILE_TIME_EVAL, frameless_function_infos_strtoupper, NULL)
ZEND_RAW_FENTRY("strtolower", zif_strtolower, arginfo_strtolower,
ZEND_ACC_COMPILE_TIME_EVAL, frameless_function_infos_strtolower, NULL)
- ZEND_FE(str_increment, arginfo_str_increment)
- ZEND_FE(str_decrement, arginfo_str_decrement)
+ ZEND_RAW_FENTRY("str_increment", zif_str_increment, arginfo_str_increment,
ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
+ ZEND_RAW_FENTRY("str_decrement", zif_str_decrement, arginfo_str_decrement,
ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
ZEND_FE(basename, arginfo_basename)
ZEND_RAW_FENTRY("dirname", zif_dirname, arginfo_dirname, 0,
frameless_function_infos_dirname, NULL)
ZEND_FE(pathinfo, arginfo_pathinfo)
diff --git a/ext/standard/basic_functions_decl.h b/ext/standard/basic_functions_decl.h
index aab4e4b5f09e..7ed3c749a28d 100644
--- a/ext/standard/basic_functions_decl.h
+++ b/ext/standard/basic_functions_decl.h
@@ -1,8 +1,8 @@
/* This is a generated file, edit basic_functions.stub.php instead.
- * Stub hash: b67e9418e158d5726b6a54d446b816264c747116 */
+ * Stub hash: 9e08e1c2517576dbce825322fe93cbce3054f23e */
-#ifndef ZEND_BASIC_FUNCTIONS_DECL_b67e9418e158d5726b6a54d446b816264c747116_H
-#define ZEND_BASIC_FUNCTIONS_DECL_b67e9418e158d5726b6a54d446b816264c747116_H
+#ifndef ZEND_BASIC_FUNCTIONS_DECL_9e08e1c2517576dbce825322fe93cbce3054f23e_H
+#define ZEND_BASIC_FUNCTIONS_DECL_9e08e1c2517576dbce825322fe93cbce3054f23e_H
typedef enum zend_enum_SortDirection {
ZEND_ENUM_SortDirection_Ascending = 1,
@@ -20,4 +20,4 @@ typedef enum zend_enum_RoundingMode {
ZEND_ENUM_RoundingMode_PositiveInfinity = 8,
} zend_enum_RoundingMode;
-#endif /* ZEND_BASIC_FUNCTIONS_DECL_b67e9418e158d5726b6a54d446b816264c747116_H */
+#endif /* ZEND_BASIC_FUNCTIONS_DECL_9e08e1c2517576dbce825322fe93cbce3054f23e_H */