On 25 February 2016 at 13:02, Dmitry Stogov <dmi...@zend.com> wrote: > > I've just got to know about possible usage of "@" in unpack(), but it seems > doesn't work at all > > $ sapi/cli/php -r 'var_dump(unpack("@0l", "\x01\x00\x00\x00")); ' > array(0) { > } > > Do I use it properly? > > Thanks. Dmitry. >
As Nikita said, you need the "/". I use this operator when processing streams of binary data. Trimmed down example: while ($blocks--) { list(, $x0, $x1, $x2, $x3) = unpack("@$offset/N4", $message); //... $offset += 16; } The dynamic format string is kind of nasty though, so no objections to an additional parameter making things clearer, however, what is to be done if an offset is specified in both the format string and the additional parameter? Does one override the other? Are they additive? -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php