[php-src] master: ext/standard: Make ltrim() and rtrim() frameless
| From: | Weilin Du | Date: | Sat, 05 Sep 2026 10:15:57 +0000 |
| Subject: | [php-src] master: ext/standard: Make ltrim() and rtrim() frameless | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141080@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-09-05T18:13:39+08:00
Commit: https://github.com/php/php-src/commit/66c98704e27c7a34a816496e86db95e9cdbbe5a2
Raw diff: https://github.com/php/php-src/commit/66c98704e27c7a34a816496e86db95e9cdbbe5a2.diff
ext/standard: Make ltrim() and rtrim() frameless
Changed paths:
M ext/standard/basic_functions.stub.php
M ext/standard/basic_functions_arginfo.h
M ext/standard/basic_functions_decl.h
M ext/standard/string.c
Diff:
diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php
index 8ae94d8c6d99..6b3b11a5fa3e 100644
--- a/ext/standard/basic_functions.stub.php
+++ b/ext/standard/basic_functions.stub.php
@@ -2331,13 +2331,21 @@ function strcoll(string $string1, string $string2): int {}
*/
function trim(string $string, string $characters = " \f\n\r\t\v\0"): string {}
-/** @compile-time-eval */
+/**
+ * @compile-time-eval
+ * @frameless-function {"arity": 1}
+ * @frameless-function {"arity": 2}
+ */
function rtrim(string $string, string $characters = " \f\n\r\t\v\0"): string {}
/** @alias rtrim */
function chop(string $string, string $characters = " \f\n\r\t\v\0"): string {}
-/** @compile-time-eval */
+/**
+ * @compile-time-eval
+ * @frameless-function {"arity": 1}
+ * @frameless-function {"arity": 2}
+ */
function ltrim(string $string, string $characters = " \f\n\r\t\v\0"): string {}
/**
diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h
index 4bcf008f5fdd..7d9a42460534 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: 31018a787ba261316941b0d88f090b9cf271aa0e
+ * Stub hash: 4feeab72edf6b7440af99a60e1401492828f141e
* Has decl header: yes */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
@@ -2238,6 +2238,22 @@ static const zend_frameless_function_info frameless_function_infos_trim[] = {
{ 0 },
};
+ZEND_FRAMELESS_FUNCTION(rtrim, 1);
+ZEND_FRAMELESS_FUNCTION(rtrim, 2);
+static const zend_frameless_function_info frameless_function_infos_rtrim[] = {
+ { ZEND_FRAMELESS_FUNCTION_NAME(rtrim, 1), 1 },
+ { ZEND_FRAMELESS_FUNCTION_NAME(rtrim, 2), 2 },
+ { 0 },
+};
+
+ZEND_FRAMELESS_FUNCTION(ltrim, 1);
+ZEND_FRAMELESS_FUNCTION(ltrim, 2);
+static const zend_frameless_function_info frameless_function_infos_ltrim[] = {
+ { ZEND_FRAMELESS_FUNCTION_NAME(ltrim, 1), 1 },
+ { ZEND_FRAMELESS_FUNCTION_NAME(ltrim, 2), 2 },
+ { 0 },
+};
+
ZEND_FRAMELESS_FUNCTION(implode, 1);
ZEND_FRAMELESS_FUNCTION(implode, 2);
static const zend_frameless_function_info frameless_function_infos_implode[] = {
@@ -3178,9 +3194,9 @@ static const zend_function_entry ext_functions[] = {
#endif
ZEND_RAW_FENTRY("strcoll", zif_strcoll, arginfo_strcoll, ZEND_ACC_DEPRECATED, NULL,
NULL)
ZEND_RAW_FENTRY("trim", zif_trim, arginfo_trim, ZEND_ACC_COMPILE_TIME_EVAL,
frameless_function_infos_trim, NULL)
- ZEND_RAW_FENTRY("rtrim", zif_rtrim, arginfo_rtrim, ZEND_ACC_COMPILE_TIME_EVAL, NULL,
NULL)
+ ZEND_RAW_FENTRY("rtrim", zif_rtrim, arginfo_rtrim, ZEND_ACC_COMPILE_TIME_EVAL,
frameless_function_infos_rtrim, NULL)
ZEND_RAW_FENTRY("chop", zif_rtrim, arginfo_chop, 0, NULL, NULL)
- ZEND_RAW_FENTRY("ltrim", zif_ltrim, arginfo_ltrim, ZEND_ACC_COMPILE_TIME_EVAL, NULL,
NULL)
+ ZEND_RAW_FENTRY("ltrim", zif_ltrim, arginfo_ltrim, ZEND_ACC_COMPILE_TIME_EVAL,
frameless_function_infos_ltrim, NULL)
ZEND_RAW_FENTRY("wordwrap", zif_wordwrap, arginfo_wordwrap, ZEND_ACC_COMPILE_TIME_EVAL,
NULL, NULL)
ZEND_RAW_FENTRY("explode", zif_explode, arginfo_explode, ZEND_ACC_COMPILE_TIME_EVAL,
NULL, NULL)
ZEND_RAW_FENTRY("implode", zif_implode, arginfo_implode, ZEND_ACC_COMPILE_TIME_EVAL,
frameless_function_infos_implode, NULL)
diff --git a/ext/standard/basic_functions_decl.h b/ext/standard/basic_functions_decl.h
index db81e0bfc077..d60317766993 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: 31018a787ba261316941b0d88f090b9cf271aa0e */
+ * Stub hash: 4feeab72edf6b7440af99a60e1401492828f141e */
-#ifndef ZEND_BASIC_FUNCTIONS_DECL_31018a787ba261316941b0d88f090b9cf271aa0e_H
-#define ZEND_BASIC_FUNCTIONS_DECL_31018a787ba261316941b0d88f090b9cf271aa0e_H
+#ifndef ZEND_BASIC_FUNCTIONS_DECL_4feeab72edf6b7440af99a60e1401492828f141e_H
+#define ZEND_BASIC_FUNCTIONS_DECL_4feeab72edf6b7440af99a60e1401492828f141e_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_31018a787ba261316941b0d88f090b9cf271aa0e_H */
+#endif /* ZEND_BASIC_FUNCTIONS_DECL_4feeab72edf6b7440af99a60e1401492828f141e_H */
diff --git a/ext/standard/string.c b/ext/standard/string.c
index af3f6a461dcf..2d868513e4ad 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -651,6 +651,34 @@ PHP_FUNCTION(rtrim)
}
/* }}} */
+ZEND_FRAMELESS_FUNCTION(rtrim, 1)
+{
+ zval str_tmp;
+ zend_string *str;
+
+ Z_FLF_PARAM_STR(1, str, str_tmp);
+
+ ZVAL_STR(return_value, php_trim_int(str, /* what */ NULL, /* what_len */ 0, /* mode */ 2));
+
+flf_clean:
+ Z_FLF_PARAM_FREE_STR(1, str_tmp);
+}
+
+ZEND_FRAMELESS_FUNCTION(rtrim, 2)
+{
+ zval str_tmp, what_tmp;
+ zend_string *str, *what;
+
+ Z_FLF_PARAM_STR(1, str, str_tmp);
+ Z_FLF_PARAM_STR(2, what, what_tmp);
+
+ ZVAL_STR(return_value, php_trim_int(str, ZSTR_VAL(what), ZSTR_LEN(what), /* mode */ 2));
+
+flf_clean:
+ Z_FLF_PARAM_FREE_STR(1, str_tmp);
+ Z_FLF_PARAM_FREE_STR(2, what_tmp);
+}
+
/* {{{ Strips whitespace from the beginning of a string */
PHP_FUNCTION(ltrim)
{
@@ -658,6 +686,34 @@ PHP_FUNCTION(ltrim)
}
/* }}} */
+ZEND_FRAMELESS_FUNCTION(ltrim, 1)
+{
+ zval str_tmp;
+ zend_string *str;
+
+ Z_FLF_PARAM_STR(1, str, str_tmp);
+
+ ZVAL_STR(return_value, php_trim_int(str, /* what */ NULL, /* what_len */ 0, /* mode */ 1));
+
+flf_clean:
+ Z_FLF_PARAM_FREE_STR(1, str_tmp);
+}
+
+ZEND_FRAMELESS_FUNCTION(ltrim, 2)
+{
+ zval str_tmp, what_tmp;
+ zend_string *str, *what;
+
+ Z_FLF_PARAM_STR(1, str, str_tmp);
+ Z_FLF_PARAM_STR(2, what, what_tmp);
+
+ ZVAL_STR(return_value, php_trim_int(str, ZSTR_VAL(what), ZSTR_LEN(what), /* mode */ 1));
+
+flf_clean:
+ Z_FLF_PARAM_FREE_STR(1, str_tmp);
+ Z_FLF_PARAM_FREE_STR(2, what_tmp);
+}
+
/* {{{ Wraps buffer to selected number of characters using string break char */
PHP_FUNCTION(wordwrap)
{