rfc:add_str_begin_and_end_functions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:add_str_begin_and_end_functions [2019/06/18 18:39] – Updated to reflect feedback obtained during the github PR process wkhudgins92 | rfc:add_str_begin_and_end_functions [2019/07/22 08:47] (current) – Close voting nikic | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Add str begin and end functions ====== | + | ====== PHP RFC: Add str_starts_with(), |
- | * Version: 0.2 | + | * Version: 0.4 |
* Date: 2016-08-01 (use today' | * Date: 2016-08-01 (use today' | ||
* Author: Will Hudgins, will@wkhudgins.info | * Author: Will Hudgins, will@wkhudgins.info | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 10: | Line 10: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | Add str_begins(), str_ibegins(), str_ends(), str_iends(), mb_str_begins(), mb_str_ibegins(), mb_str_ends(), and mb_str_iends() functions | + | Add str_starts_with(), str_starts_with_ci(), str_ends_with(), str_ends_with_ci(), mb_str_starts_with(), mb_str_starts_with_ci(), mb_str_ends_with(), and mb_str_ends_with_ci() functions: |
- | boolean str_begins[(string $haystack, string $needle)] | + | < |
- | | + | function str_starts_with(string $haystack, string $needle): bool |
- | | + | function str_starts_with_ci(string $haystack, string $needle): bool |
- | | + | function str_ends_with(string $haystack, string $needle): bool |
- | | + | function str_ends_with_ci(string $haystack, string $needle): bool |
- | | + | function mb_str_starts_with(string $haystack, string $needle [, string $encoding]): bool |
- | | + | function mb_str_starts_with_ci(string $haystack, string $needle [, string $encoding]): bool |
- | | + | function mb_str_ends_with(string $haystack, string $needle [, string $encoding]): bool |
+ | function mb_str_ends_with_ci(string $haystack, string $needle [, string $encoding]): bool | ||
+ | </ | ||
| | ||
- | str_begins() checks if $haystack begins with $needle. It accomplishes this by comparing each character in $haystack with the corresponding character in $needle. If any of the characters do not match, it will return false. | + | str_starts_with() checks if $haystack begins with $needle. It accomplishes this by comparing each character in $haystack with the corresponding character in $needle. If any of the characters do not match, it will return false. |
- | str_ibegins() and str_iends() do the same thing, except they are case insensitive. | + | str_starts_with_ci() and str_ends_with_ci() do the same thing, except they are case insensitive. |
The mb_* versions of these method function very similar except they make use of the mbfl_strpos() function or the php_mb_stripos() helper function. | The mb_* versions of these method function very similar except they make use of the mbfl_strpos() function or the php_mb_stripos() helper function. | ||
Examples below: | Examples below: | ||
- | | + | |
- | if (str_begin(" | + | < |
- | echo "This condition would be true"; | + | $str = " |
- | | + | if (str_starts_with($str, " |
- | | + | echo "This condition would be true"; |
- | | + | if (str_starts_with($str, " |
- | | + | echo "This condition would not be true"; |
- | | + | if (str_starts_with_ci($str, " |
- | | + | echo "This condition would be true"; |
- | | + | if (str_starts_with_ci($str, " |
- | echo "This condition would be true"; | + | echo "This condition would also be true"; |
- | | + | if (str_ends_with($str, " |
- | | + | echo "This condition would be true"; |
- | | + | if (str_ends_with($str, " |
- | | + | echo "This condition would not be true"; |
- | | + | if (str_ends_with_ci($str, " |
- | | + | echo "This condition would be true"; |
+ | if (str_ends_with_ci($str, " | ||
+ | echo "This condition would also be true"; | ||
+ | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | None. | + | This could break functions existing in userland with the same names. |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | Next PHP 7.x release. | + | Next eligible |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 57: | Line 62: | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Adds mb_str_begins(), mb_str_ibegins(), mb_str_ends(), and mb_str_iends() to the mbstring extension. | + | Adds mb_str_starts_with(), mb_str_starts_with_ci(), mb_str_ends_with(), and mb_str_ends_with_ci() to the mbstring extension. |
==== To Opcache ==== | ==== To Opcache ==== | ||
Line 76: | Line 81: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
+ | |||
Once this feature is approved and added, it will not need any future improvements. | Once this feature is approved and added, it will not need any future improvements. | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | This project requires a 2/3 majority to be approved. | + | |
+ | Voting closes 2019-07-20. | ||
+ | |||
+ | <doodle | ||
+ | title=" | ||
+ | * yes | ||
+ | * no | ||
+ | </doodle> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <doodle | ||
+ | title=" | ||
+ | * yes | ||
+ | * no | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 91: | Line 112: | ||
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | + | Implementation of similar methods/ |
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | http:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
Related feature request: [[bugid@50434]]. | Related feature request: [[bugid@50434]]. |
rfc/add_str_begin_and_end_functions.1560883147.txt.gz · Last modified: 2019/06/18 18:39 by wkhudgins92