Conversation
|
Error text: The error occurs due to the declaration of the str_contains function in file2.php |
|
Tests don't break anymore! |
| } | ||
|
|
||
| bool f$str_contains(const string &haystack, const string &needle) { | ||
| return haystack.contains(needle); |
There was a problem hiding this comment.
What are the advantages of implementing it as a new functions instead of using already existing strpos?
PHP uses similar approach:
https://github.com/php/php-src/blob/0b6f58d907e7169f7876bbea199967262197fbaa/ext/standard/string.c#L1794
As seen in the code below, str_contains could be implemented in terms of strpos like so:
return '' === $needle || false !== strpos($haystack, $needle);I would check what php_memnstr from PHP is. Maybe we have compatible function. If not, we could add one and use it in places where PHP uses it.
Maybe php_memnstr is identical to the newly introduced contains method, but I suggest re-checking that.
Also: you can run benchmarks using ktest utility.
https://habr.com/ru/company/vk/blog/572424/
Information
Example