Hi
Am 2025-06-11 11:58, schrieb Christian Schneider:
Am 10.06.2025 um 21:46 schrieb Hans Henrik Bergan <h...@loltek.net>:
Can we make str_(starts|ends)_with variadic?
```
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
}
```
[…]
Which leaves me +-0 on this,
- Chris
I agree that the examples are not particularly well-chosen, because the
correct implementation for the two examples would be:
if (\in_array(\pathinfo($filename, PATHINFO_EXTENSION), ['pdf',
'doc', 'docx'], true)) { }
and
if (\in_array(\Uri\Rfc3986\Uri::parse($url)?->getScheme(), ['http',
'https'], true)) { }
and then leaving it up to the code developers / the engien to possibly
optimize `\in_array()` into `match()` or similar when only a small
number of values need to be matched.
Best regards
Tim Düsterhus