go to bug id or search bugs for
I can be wrong, but documentation says that "a" and "Z" are equal since PHP 5.5
But it is not:
php > var_dump(pack('a1', '1'));
php > var_dump(pack('Z1', '1'));
If I'm wrong, please point to correct docs.
var_dump(pack('a1', '1') === pack('Z1', '1'));
Add a Patch
Add a Pull Request
In this case the correct docs are Perl's :D
We're borrowing pack/unpack from them anyways, and their explanations go more in depth. Maybe we should link to them...
a A string with arbitrary binary data, will be null padded.
Z A null-terminated (ASCIZ) string, will be null padded.
The a , A , and Z types gobble just one value, but pack it as a string of length
count, padding with nulls or spaces as needed. When unpacking, A strips trailing
whitespace and nulls, Z strips everything after the first null, and a returns
data with no stripping at all.
If the value to pack is too long, the result is truncated. If it's too long and
an explicit count is provided, Z packs only $count-1 bytes, followed by a null
byte. Thus Z always packs a trailing null, except when the count is 0.
I think we can fit the terminating NUL and truncation behavior briefly in the table. Something like "NUL-padded string; always includes at least one NUL terminator". (The "new in PHP 5.5" is covered in the Changelog already.) Or just mention the terminator and add a Note?
One more small change to make: the `format` description says
> For a, A, h, H the repeat count specifies how many characters of one data
> argument are taken,
That applies to Z too.