Skip to content

Commit fdc2e48

Browse files
committed
add str_contains function
1 parent 689b8e3 commit fdc2e48

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Php80.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public static function preg_last_error_msg(): string
4545
return 'Unknown error';
4646
}
4747
}
48+
49+
public static function str_contains(string $haystack, string $needle): bool
50+
{
51+
return '' === $needle || false !== strpos($haystack, $needle);
52+
}
4853
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This component provides features added to PHP 8.0 core:
88
- `ValueError` class
99
- `FILTER_VALIDATE_BOOL` constant
1010
- [`preg_last_error_msg`](https://php.net/preg_last_error_msg)
11+
- [`str_contains`](https://php.net/str_contains)
1112

1213
More information can be found in the
1314
[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md).

bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ function fdiv(float $dividend, float $divisor): float { return p\Php80::fdiv($di
2020
function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); }
2121
}
2222

23+
if (!function_exists('str_contains')) {
24+
function str_contains(string $haystack, string $needle): bool { return p\Php80::str_contains($haystack, $needle); }
25+
}
26+
2327
if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) {
2428
define('FILTER_VALIDATE_BOOL', FILTER_VALIDATE_BOOLEAN);
2529
}

0 commit comments

Comments
 (0)