Can we make str_(starts|ends)_with variadic?

From: Date: Tue, 10 Jun 2025 19:46:52 +0000
Subject: Can we make str_(starts|ends)_with variadic?
Groups: php.internals 
Request: Send a blank email to internals+get-127637@lists.php.net to get a copy of this message
Can we make str_(starts|ends)_with variadic? PR: https://github.com/php/php-src/pull/18825 Code like ```php if (str_starts_with($url, "http://") || str_starts_with($url, "https://")) { // url } if (str_ends_with($filename, ".pdf") || str_ends_with($filename, ".doc") || str_ends_with($filename, ".docx")) { // document } $isValidExtension = false; foreach ($validExtensions as $needle) { if (str_ends_with($str, $needle)) { $isValidExtension = true; break; } } if ($isValidExtension) { // valid extension } ``` could then be replaced with ``` if (str_starts_with($url, "http://", "https://")) { // url } if (str_ends_with($filename, ".pdf", ".doc", ".docx")) { // document } if(str_ends_with($str, ...$validExtensions){ // valid extension } ``` Fwiw Python support str.endswith((".pdf", ".doc", ".docx"))

« previous php.internals (#127637) next »