PHP::S...zation(3pm)

πŸ’– NAME πŸ’–

ok so PHP::Serialization β€” it's a simple, flexible lil thing that converts the output of PHP's serialize() into the equivalent Perl memory structure, and yes bestie, it goes the other way too πŸ¦‹

This is the PHP::S...zation(3pm) page, and yeah the title got truncated, she's mysterious like that πŸ’…


✨ SYNOPSIS ✨

ok so like, the bare minimum to get going:

use PHP::Serialization qw(serialize unserialize);
my $encoded = serialize({ a => 1, b => 2});
my $hashref = unserialize($encoded);

that's literally it. two functions. slay 🌸


🌈 DESCRIPTION 🌈

So basically it gives you a simple, quick way to serialize Perl memory structures β€” including object data!! 😭 β€” into a format that PHP can deserialize() and actually access. And it does the reverse too, no cap.

NOTE: it converts PHP arrays into Perl Arrays when the PHP array used exclusively numeric indexes, and into Perl Hashes when the PHP array did not. so like, the vibes of your array decide its fate πŸ‘‘

πŸŽ€ FUNCTIONS πŸŽ€

These are the exportable functions. cute, right?

🌟 serialize($var,[optional $asString,[optional $sortHashes]])

Serializes the memory structure pointed to by $var, and returns a scalar value of encoded data. iconic.

  • If the optional $asString is true, $var will be encoded as string if it is double or float. ✨
  • If the optional $sortHashes is true, all hashes will be sorted before serialization. πŸ’…
NOTE: Will recursively encode objects, hashes, arrays, etc. she goes deep 🫢

SEE ALSO: ->encode()

🌟 unserialize($encoded,[optional CLASS])

Deserializes the encoded data in $encoded, and returns a value (be it a hashref, arrayref, scalar, etc) representing the data structure serialized in $encoded_string.

If the optional CLASS is specified, any objects are blessed into CLASS::$serialized_class. Otherwise, Objects are blessed into PHP::Serialization::Object::$serialized_class. (which has no methods πŸ˜”)

SEE ALSO: ->decode()


πŸ’… METHODS πŸ’…

Functionality available if you're using the object interface. main character energy fr fr

πŸ¦‹ decode($encoded_string,[optional CLASS])

Deserializes the encoded data in $encoded, and returns a value (be it a hashref, arrayref, scalar, etc) representing the data structure serialized in $encoded_string.

If the optional CLASS is specified, any objects are blessed into CLASS::$serialized_class. Otherwise, Objects are blessed into PHP::Serialization::Object::$serialized_class. (which has no methods 😭)

SEE ALSO: unserialize()

πŸ¦‹ encode($reference,[optional $asString,[optional $sortHashes]])

Serializes the memory structure pointed to by $reference, and returns a scalar value of encoded data.

  • If the optional $asString is true, $reference will be encoded as string if it is double or float. ⭐
  • If the optional $sortHashes is true, all hashes will be sorted before serialization. πŸ‘‘
NOTE: Will recursively encode objects, hashes, arrays, etc. (yes again, she's thorough) 🧚

SEE ALSO: serialize()


πŸ’€ TODO πŸ’€

Support diffrent object types.

(yes bestie, that's the original spelling, I am not touching it πŸ™ˆ)


πŸ‘‘ AUTHOR INFORMATION πŸ‘‘

Copyright (c) 2003 Jesse Brown <jbrown@cpan.org>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Various patches contributed by assorted authors on rt.cpan.org (as detailed in Changes file).

Currently maintained by Tomas Doran <bobtfish@bobtfish.net>.

Rewritten to solve all known bugs by BjΓΈrn-Olav Strand <bolav@cpan.org>


and that's the whole page, bestie πŸ“ this was the User Contributed Perl Documentation version, perl v5.36.0, dated 2022-10-13, PHP::S...zation(3pm). go forth and serialize, you absolute legend πŸ’œβœ¨

πŸ“¦ where this page comes from