Commit 027a5f85364 for php.net
commit 027a5f8536468498a659684cf273d4f8bdd06706
Author: Weilin Du <weilindu@php.net>
Date: Mon Aug 31 00:19:57 2026 +0800
ext/standard: Make `str_ends_with` frameless (#23510)
Since str_starts_with is frameless, str_ends_with also
should be frameless.
diff --git a/UPGRADING b/UPGRADING
index a164599c6f1..5a5cafc0234 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -973,6 +973,7 @@ PHP 8.6 UPGRADE NOTES
. Reduced temporary allocations when iterating Phar directories.
- Standard:
+ . Improved performance of str_ends_with().
. Improved performance of array_fill_keys().
. Improved performance of array_intersect().
. Improved performance of array_map() with multiple arrays passed.
diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php
index 3e23934cbc7..8ae94d8c6d9 100644
--- a/ext/standard/basic_functions.stub.php
+++ b/ext/standard/basic_functions.stub.php
@@ -2451,7 +2451,10 @@ function str_contains(string $haystack, string $needle): bool {}
*/
function str_starts_with(string $haystack, string $needle): bool {}
-/** @compile-time-eval */
+/**
+ * @compile-time-eval
+ * @frameless-function {"arity": 2}
+ */
function str_ends_with(string $haystack, string $needle): bool {}
/**
diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h
index 442085e9d6c..4bcf008f5fd 100644
Binary files a/ext/standard/basic_functions_arginfo.h and b/ext/standard/basic_functions_arginfo.h differ
diff --git a/ext/standard/basic_functions_decl.h b/ext/standard/basic_functions_decl.h
index f2f234f60cc..db81e0bfc07 100644
Binary files a/ext/standard/basic_functions_decl.h and b/ext/standard/basic_functions_decl.h differ
diff --git a/ext/standard/string.c b/ext/standard/string.c
index e5307a4f2d4..af3f6a461dc 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -1895,6 +1895,21 @@ PHP_FUNCTION(str_ends_with)
}
/* }}} */
+ZEND_FRAMELESS_FUNCTION(str_ends_with, 2)
+{
+ zval haystack_tmp, needle_tmp;
+ zend_string *haystack, *needle;
+
+ Z_FLF_PARAM_STR(1, haystack, haystack_tmp);
+ Z_FLF_PARAM_STR(2, needle, needle_tmp);
+
+ RETVAL_BOOL(zend_string_ends_with(haystack, needle));
+
+flf_clean:
+ Z_FLF_PARAM_FREE_STR(1, haystack_tmp);
+ Z_FLF_PARAM_FREE_STR(2, needle_tmp);
+}
+
static zend_always_inline void _zend_strpos(zval *return_value, zend_string *haystack, zend_string *needle, zend_long offset)
{
const char *found = NULL;