Task #63929
closed
Deprecate usage of GeneralUtility::isFirstPartOfStr()
Added by Stefan Neufeind almost 10 years ago.
Updated over 8 years ago.
Description
Use StringUtility::beginsWith() instead, which behaves "almost" identical but with some added checks.
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35513
- Sprint Focus set to On Location Sprint
- Status changed from Under Review to Accepted
- Target version set to 7.5
The proper solution here is to get rid of isFirstPartOfStr by applying the following logic:
The following 'rules' should used for the replacement:
- Drop isFirstPartOfStr / StringUtility::beginsWith in favor of any occurence of
strpos(haystack, needle) === 0
strpos(haystack, needle, 0) === 0
- Drop isFirstPartOfStr / StringUtility::beginsWith in favor of any occurence of
substr(haystack, 0, strlen(needle)) === needle
- Use variable{x} for any occurence of
substr(string, x, 1)
- Use array methods, when the string methods are simulating
an explode or check substr with the third parameter set to TRUE
Once all places are replaced (see related issue), then we can proceed here.
Note that substr($s, 0, 1), in case of NULL or an empty string, will return false - while simply accessing the index would at least trigger a notice.
beginsWith handles some edge-cases as well.
So let's check for NULL and '' in these cases, to avoid the warning, since they are rare compared to the first example anyway.
- Sprint Focus deleted (
On Location Sprint)
- Target version deleted (
7.5)
- Status changed from Accepted to Rejected
patch didn't make it and was not pushed forward. closed issue for now, feel free to further work on it if needed.
Also available in: Atom
PDF