1.2.598. Invalid Pack Format

Some characters are invalid in a pack() format string.

pack() and unpack() accept the following format specifiers : aAhHcCsSnviIlLNVqQJPfgGdeExXZ.

unpack() also accepts a name after the format specifier and an optional quantifier.

All other situations is not a valid, and produces a warning : pack(): Type t: unknown format code Check pack() documentation for format specifiers that were introduced in various PHP version, namely 7.0, 7.1 and 7.2.

<?php
    $binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66);

    // the first unsigned short is stored as 'first'. The next matches are names with numbers.
    $res = unpack('nfirst/vc*', $binarydata);
?>

See also pack and unpack.

1.2.598.1. Suggestions

  • Fix the packing format with correct values

1.2.598.2. Specs

Short name

Structures/InvalidPackFormat

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior

Exakat since

1.4.9

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

High

Features

pack

Available in

Entreprise Edition, Community Edition, Exakat Cloud