Task #37784

Evaluate whether using substr_compare() instead substr()===

Added by Adrian Föder about 3 years ago. Updated over 2 years ago.

Status:Rejected Start date:2012-06-06
Priority:Could have Due date:
Assigned To:Karsten Dambekalns % Done:

0%

Category:-
Target version:-
Sprint: Has patch:No
PHP Version: Complexity:

Description

consider using http://php.net/manual/function.substr-compare.php globally as preference over substr()

As a side note I'd still suggest introducing a Utilities method for comparing the beginning sequence, in order to avoid the pretty complicated and unintuitive handling of the substr_compare return values.

History

#1 Updated by Christian Müller about 3 years ago

we should maybe make a quick statistic about speed in static call to Utility function vs. substr vs. substr_compare

#2 Updated by Karsten Dambekalns about 3 years ago

  • Status changed from New to Accepted
  • Assigned To set to Karsten Dambekalns

#3 Updated by Karsten Dambekalns about 3 years ago

  • Status changed from Accepted to Needs Feedback

Adrian, why did you suggest this? I made a quick and dirty comparison, and substr_compare() seems to be significantly slower. Feel free to have a look at https://gist.github.com/3098900 and see if my test makes sense.

Also, the use of substr_compare() is everything but intuitive…

#4 Updated by Adrian Föder about 3 years ago

Karsten, thanks for actually checking this; the reason why I suggested this was because of http://www.rvantwisk.nl/flow3-irc-log/2012/june/6.html 08:32 ;-)

Without reading the log further, I initially thought about a t3lib_div::isFirstPartOfStr derivate in FLOW3 that checks for the beginning of a string or, like your gist recommends, for the ending.
Could be kinda Utility\Strings::beginsWith('TYPO3_FLOW3_Foo', 'TYPO3') or ::endsWith().
This would increase code readability fantastically IMO in order to avoid constructs like strpos($foo, 0, strlen('TYPO3')), if that is right (pseudo-code).

#5 Updated by Adrian Föder over 2 years ago

  • Status changed from Needs Feedback to Rejected

Also available in: Atom PDF