1.2.667. Mbstring Third Arg

Some mbstring functions use the third argument for offset, not for encoding.

Those are the following functions :

<?php

// Display BC
echo mb_substr('ABC', 1 , 2, 'UTF8');

// Yields Warning: mb_substr() expects parameter 3 to be int, string given
// Display 0 (aka, substring from 0, for length (int) 'UTF8' => 0)
echo mb_substr('ABC', 1 ,'UTF8');

?>

1.2.667.1. Suggestions

  • Add a third argument

  • Use the default encoding (aka, omit both third AND fourth argument)

1.2.667.2. Specs

Short name

Structures/MbstringThirdArg

Rulesets

All, Analyze, CE, CI-checks

Exakat since

1.9.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

mbstring

Available in

Entreprise Edition, Community Edition, Exakat Cloud