Add array_str_contains() function to standard library - #23512
Add array_str_contains() function to standard library#23512sepehrphpr wants to merge 15 commits into
Conversation
|
Hi @sepehrphpr just personal take, it is a hard sell. Some people will likely question some design choices (e.g. it drops everything silently as opposed to str_contains ... what about case insensitiveness ? ...). Therefore I invite you to discuss its merit(s) on the internal mailing list at least. |
|
CI is red, But it is not CI's timeout. Test case is wrong. |
|
I think this needs more design discussion before the implementation can be reviewed meaningfully. This introduces a new standard library function, but the semantics are not obvious to me. In particular, silently dropping non-string values makes this behave differently from applying str_contains() in userland, and the expected behavior around case sensitivity, coercion, and mixed arrays probably needs to be agreed first. |
Summary
This PR introduces the
array_str_contains(array $haystack, string $needle): arrayfunction to the standard library for PHP 8.7.Motivation
Filtering arrays based on substring matching is a very common task in PHP applications. Currently, developers often use: