1.2.718. Mono Or Multibytes Favorite

PHP handles strings wity bytes, and also support multibytes with the mbstring extension. This analysis reports when the mono or the multi byte version has dominance.

The dominant one is reported when it has over 90% of usage. The remaining cases should be uniformed, so has to make this code consistent. Sometimes, the same code may make usage of both the versions, depending on the manipulated string. For example, array index as single bytes strings, while user labels as multi-bytes.

The following functions are used for the analysis :

This rule doesn’t detect mb_string overloading, which remplace some of the mono-bytes functions by their mbstring counterpart, without changing the calls in the code.

<?php

echo strlen($string) . PHP_EOL;

echo mb_strlen($string) . PHP_EOL;

?>

1.2.718.1. Suggestions

  • Make the code uniform by using one of the two versions of string functions

1.2.718.2. Specs

Short name

Structures/strOrMbFavorite

Rulesets

All, Preferences

Exakat since

2.5.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Available in

Entreprise Edition, Exakat Cloud