Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

288
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda