Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda