Project

General

Profile

Actions

Task #63929

closed

Deprecate usage of GeneralUtility::isFirstPartOfStr()

Added by Stefan Neufeind almost 10 years ago. Updated over 8 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Code Cleanup
Target version:
-
Start date:
2014-12-16
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

Use StringUtility::beginsWith() instead, which behaves "almost" identical but with some added checks.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Task #54517: Replace substr() and strpos() with GeneralUtility::isFirstPartOfString when it makes senseRejectedJo Hasenau2013-12-19

Actions
Actions #1

Updated by Gerrit Code Review almost 10 years ago

  • 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

Actions #2

Updated by Anja Leichsenring almost 10 years ago

  • Sprint Focus set to On Location Sprint
Actions #3

Updated by Benni Mack almost 10 years ago

  • 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.

Actions #4

Updated by Stefan Neufeind almost 10 years ago

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.

Actions #5

Updated by Jo Hasenau almost 10 years ago

So let's check for NULL and '' in these cases, to avoid the warning, since they are rare compared to the first example anyway.

Actions #6

Updated by Benni Mack almost 10 years ago

  • Sprint Focus deleted (On Location Sprint)
Actions #7

Updated by Benni Mack about 9 years ago

  • Target version deleted (7.5)
Actions #8

Updated by Christian Kuhn over 8 years ago

  • 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.

Actions

Also available in: Atom PDF