Evaluate whether using substr_compare() instead substr()===
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.
Updated by Karsten Dambekalns over 9 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…
Updated by Adrian Föder over 9 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).