Nathan Nobbe dedi ki:

> all,
> 
> i have recently stumbled upon the
> pack<http://www.php.net/manual/en/function.pack.php>method.
> can this be used as a substitute for
> serialize<http://www.php.net/manual/en/function.serialize.php>
> ?
> if so, is there any rationalization for this; like would it perhaps
> create a more
> compact representation of the data or run more quickly?
> it looks like pack cannot be used on object as i didnt see object in the
> format listing;
> what would be a typical application of the pack method?

I've not used serialize(), but I think it packs its input into some
proprietary (internal) format best suited to handle as a single entity
(pass it to-fro, store it in database, etc.). Ergo, a serialized entity
cannot be used as it is - you need to unserialize it back before use.
OTOH, pack() returns the internal binary representation of its input as a
binary string. This may not always be the optimal way to handle a given
collection of data as in the case for serialize(), but it enables you to
access, use and manipulate internal representations of the data, be it
just a single variable or an assorted structure.

I once used pack to obtain a 128 bit long binary string (xor key for
rudimentary file encryption) by packing four 32-bit integers into a binary
string and then using it as the xor key. (FWIW, bitwise operations work
both on integers and "strings" - binary or otherwise.)

Kind regards,
-- 
Abdullah Ramazanoglu
aramazan ÄT myrealbox D0T cöm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to