1.2.669. Mbstring Unknown Encodings

mbstring functions require one of its supported encoding as parameter.

For example, mb_chr() requires encoding as second parameter. The supported encodings are available with mb_list_encodings() and mb_encoding_aliases().

A wrong encoding generates a fatal error. Here are some of the dropped encodings, depending on PHP versions:

  • PHP 7.0
    • auto

  • PHP 8.0
    • pass

  • PHP 8.1
    • wchar

    • byte2be

    • byte2le

    • byte4be

    • byte4le

    • jis-ms

    • cp50220raw

  • PHP 8.2
    • qprint

    • base64

    • uuencode

    • html-entities

<?php

     print mb_chr(128024, 'UTF-8')); // emoji of an elephant

     //Argument #2 ($encoding) must be a valid encoding, "elephpant" given
     print mb_chr($value, 'elephpant'));
}
?>

1.2.669.1. Suggestions

  • Use a valid encoding for the PHP version.

1.2.669.2. Specs

Short name

Structures/MbStringNonEncodings

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.5.0

Severity

Major

Time To Fix

Quick (30 mins)

Precision

High

Features

mbstring, encoding

Available in

Entreprise Edition, Exakat Cloud