Re: Fw: unpack()

From: Date: Thu, 25 Feb 2016 15:20:37 +0000
Subject: Re: Fw: unpack()
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-91408@lists.php.net to get a copy of this message
On 25 February 2016 at 13:02, Dmitry Stogov <dmitry@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?

« previous php.internals (#91408) next »