lib/danog/PHP/StructTools.php
public function unpack($format, $data)
    {
        $format = $this->padformat($format);
        $size = $this->calcsize($format);
        if (strlen($data) != $size) {
            throw new StructException('Length of given data ('.strlen($data).') is different from length calculated using format string ('.$size.').');
        }
        $dataarray = $this->data2array($format, $data);

        if ($this->array_total_strlen($dataarray) != $size) {
            throw new StructException('Length of array ('.$this->array_total_strlen($dataarray).') is different from length calculated using format string ('.$size.').');
        }
        $result = []; // Data to return
        $packcommand = $this->parseformat($format, $this->array_each_strlen($dataarray), true); // Get unpack parameters
        set_error_handler([$this, 'ExceptionErrorHandler']);
        $arraycount = 0;
        foreach ($packcommand as $key => $command) {
            if ($command['modifiers']['FORMAT_ENDIANNESS'] != $command['modifiers']['BIG_ENDIAN']) {
                $dataarray[$command['datakey']] = strrev($dataarray[$command['datakey']]);
            } // Reverse if wrong endianness
            try {
                switch ($command['phpformat']) {
                    case 'p':
                        $templength = unpack('c', $dataarray[$command['datakey']])[1];
                        $result[$arraycount] = implode('', unpack('a'.$templength, substr($dataarray[$command['datakey']], 1)));
                        break;
                    case '?':
                        if (implode('', unpack('c'.$command['count'], $dataarray[$command['datakey']])) == 0) {
                            $result[$arraycount] = false;
                        } else {
                            $result[$arraycount] = true;
                        }
                        break;

                    case 'q':
                    case 'Q':
                    case 'l':
                    case 'L':
                    case 'i':
                    case 'I':
                    case 's':
                    case 'S':
                    case 'c':
                    case 'C':
                        $result[$arraycount] = $this->num_unpack($dataarray[$command['datakey']], $command['modifiers']['SIZE'], ctype_upper($command['phpformat']));
                        break;

                    default:
                        $result[$arraycount] = implode('', unpack($command['phpformat'].$command['count'], $dataarray[$command['datakey']])); // Unpack current char
                        break;
                }
            } catch (StructException $e) {
                throw new StructException('An error occurred while unpacking data at offset '.$command['datakey'].' ('.$e->getMessage().').');
            }
            switch ($command['modifiers']['TYPE']) {
                case 'int':
                    if (!is_int($result[$arraycount]) && !is_float($result[$arraycount])) {
                        $result[$arraycount] = (int) $result[$arraycount];
                    }
/*                    if (is_float($result[$arraycount]) && $result[$arraycount] < PHP_INT_MAX) {
                        $result[$arraycount] = (int) $result[$arraycount];
                    }*/
                    break;
                case 'float':
                    if (!is_float($result[$arraycount])) {
                        $result[$arraycount] = (float) $result[$arraycount];
                    }

                    break;
                case 'unset':
                    unset($result[$arraycount]);
                    $arraycount--;
                    break;
                case 'string':
                    if (!is_string($result[$arraycount])) {
                        $result[$arraycount] = (string) $result[$arraycount];
                    }
                    break;
                case 'bool':
                    if (!is_bool($result[$arraycount])) {
                        $result[$arraycount] = (bool) $result[$arraycount];
                    }
                    break;
                default:
                    break;
            }
            $arraycount++;
        }
        restore_error_handler();

        return $result;
    }
public function unpack($format, $data)
    {
        $format = $this->padformat($format);
        $size = $this->calcsize($format);
        if (strlen($data) != $size) {
            throw new StructException('Length of given data ('.strlen($data).') is different from length calculated using format string ('.$size.').');
        }
        $dataarray = $this->data2array($format, $data);

        if ($this->array_total_strlen($dataarray) != $size) {
            throw new StructException('Length of array ('.$this->array_total_strlen($dataarray).') is different from length calculated using format string ('.$size.').');
        }
        $result = []; // Data to return
        $packcommand = $this->parseformat($format, $this->array_each_strlen($dataarray), true); // Get unpack parameters
        set_error_handler([$this, 'ExceptionErrorHandler']);
        $arraycount = 0;
        foreach ($packcommand as $key => $command) {
            if ($command['modifiers']['FORMAT_ENDIANNESS'] != $command['modifiers']['BIG_ENDIAN']) {
                $dataarray[$command['datakey']] = strrev($dataarray[$command['datakey']]);
            } // Reverse if wrong endianness
            try {
                switch ($command['phpformat']) {
                    case 'p':
                        $templength = unpack('c', $dataarray[$command['datakey']])[1];
                        $result[$arraycount] = implode('', unpack('a'.$templength, substr($dataarray[$command['datakey']], 1)));
                        break;
                    case '?':
                        if (implode('', unpack('c'.$command['count'], $dataarray[$command['datakey']])) == 0) {
                            $result[$arraycount] = false;
                        } else {
                            $result[$arraycount] = true;
                        }
                        break;

                    case 'q':
                    case 'Q':
                    case 'l':
                    case 'L':
                    case 'i':
                    case 'I':
                    case 's':
                    case 'S':
                    case 'c':
                    case 'C':
                        $result[$arraycount] = $this->num_unpack($dataarray[$command['datakey']], $command['modifiers']['SIZE'], ctype_upper($command['phpformat']));
                        break;

                    default:
                        $result[$arraycount] = implode('', unpack($command['phpformat'].$command['count'], $dataarray[$command['datakey']])); // Unpack current char
                        break;
                }
            } catch (StructException $e) {
                throw new StructException('An error occurred while unpacking data at offset '.$command['datakey'].' ('.$e->getMessage().').');
            }
            switch ($command['modifiers']['TYPE']) {
                case 'int':
                    if (!is_int($result[$arraycount]) && !is_float($result[$arraycount])) {
                        $result[$arraycount] = (int) $result[$arraycount];
                    }
/*                    if (is_float($result[$arraycount]) && $result[$arraycount] < PHP_INT_MAX) {
                        $result[$arraycount] = (int) $result[$arraycount];
                    }*/
                    break;
                case 'float':
                    if (!is_float($result[$arraycount])) {
                        $result[$arraycount] = (float) $result[$arraycount];
                    }

                    break;
                case 'unset':
                    unset($result[$arraycount]);
                    $arraycount--;
                    break;
                case 'string':
                    if (!is_string($result[$arraycount])) {
                        $result[$arraycount] = (string) $result[$arraycount];
                    }
                    break;
                case 'bool':
                    if (!is_bool($result[$arraycount])) {
                        $result[$arraycount] = (bool) $result[$arraycount];
                    }
                    break;
                default:
                    break;
            }
            $arraycount++;
        }
        restore_error_handler();

        return $result;
    }
unpack.

Unpacks data into an array

@param	$format	Format string
@param	$data	Data to decode

@return Decoded data