1.2.385. Drop Substr Last Arg

Substr() works till the end of the string when the last argument is omitted. There is no need to calculate string size to make this work.

<?php

$string = 'abcdef';

// Extract the end of the string
$cde = substr($string, 2);

// Too much work
$cde = substr($string, 2, strlen($string));

?>

1.2.385.1. Suggestions

  • Use negative length

  • Omit the last argument to get the string till its end

1.2.385.2. Specs

Short name

Structures/SubstrLastArg

Rulesets

All, Changed Behavior, Suggestions

Exakat since

1.2.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Examples

SuiteCrm, Tine20

Available in

Entreprise Edition, Exakat Cloud