Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
Avoid null bytes in php serialize()

I am serializing php objects using php serialize(). However, it adds null bytes in the result for protected member variables. This result is then passed as a message to an Amazon SQS queue. The problem is that SQS does not support null bytes in message body. Is there any way to get rid of the null bytes. I have to make sure the result is still unserializable at the other end.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I encountered the same problem while trying to serialize an object.

As explained in Michael - sqlbot comment, base64_encode function is properly handling the NUL bytes.

On the "serializing" side you should do:

base64_encode(serialize($object));

On the "deserializing" side:

unserialize(base64_decode($object));

If you want to know how the serialize function internally works, you can read PHP Internals Book: Serialization:

The \0 in the above serialization string are NUL bytes. As you can see private and protected members are serialized with rather peculiar names: Private properties are prefixed with \0ClassName\0 and protected properties with \0*\0. These names are the result of name mangling, which is something we’ll cover in a later section.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!