Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

unpack() Strips Endianness Modifiers From The Result Key

unpack() format codes accept an endianness modifier, such as < for little-endian or > for big-endian, directly after the type code. Until PHP 8.6, a modifier placed right before the slash-separated key, such as s<value, was not recognized as a modifier there and was kept as part of the resulting array key, so the key became <value instead of value. In PHP 8.6, the modifier is recognized and stripped in that position too, so the key is the clean value.

PHP code

<?php

var_dump(unpack("s<value", pack("s", 5)));

?>

Before

array(1) {
  ["<value"]=>
  int(5)
}

After

array(1) {
  ["value"]=>
  int(5)
}

PHP version change

This behavior changed in 8.6.

See Also

Extension

© 2023-2026, Damien Seguy - Exakat