1.2.1178. Substring First¶
Always start by reducing a string before applying some transformation on it. The shorter string will be processed faster. The gain produced here is greater with longer strings, or greater reductions. They may also be used in loops. This is a micro-optimisation when used on short strings and single string reductions.
This works with any reduction function instead of substr(), like trim(), iconv(), etc.
<?php
// fast version
$result = strtolower(substr($string, $offset, $length));
// slower version
$result = substr(strtolower($string), $offset, $length);
?>
1.2.1178.1. Connex PHP features¶
1.2.1178.1.1. Suggestions¶
Always reduce the string first, then apply some transformation
1.2.1178.1.2. Specs¶
Short name |
Performances/SubstrFirst |
Rulesets |
|
Exakat since |
1.0.1 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Examples |
|
Available in |