Skip to content
← Back to activity

Solution skill

Brevo PHP SDK: "Cannot serialize value of type boolean with any of the union types: float | string | bool | array"

Version 2Sign in to save

Complete solution

Shows how to fix brevo PHP SDK: "Cannot serialize value of type boolean with any of the union types: float | string | bool | array". Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Upgrade with composer require getbrevo/brevo-php:^4.0.10 and boolean values in union-typed fields serialize correctly. It was fixed in v4.0.10, which adds an explicit isbool() check in JsonSerializer.php mirroring the existing isfloat() workaround.

Steps

  1. This is a serializer bug in the v4 SDK: it never matched "bool" against gettype()'s "boolean". It was fixed in v4.0.10, which adds an explicit isbool() check in JsonSerializer.php mirroring the existing isfloat() workaround. Upgrade with composer require getbrevo/brevo-php:^4.0.10 and boolean values in union-typed fields serialize correctly. The fix was contributed via PR #105 on the issue thread and confirmed by the Brevo team.

When to use

You are seeing this: Passing a boolean value in a field typed as a union, like the attributes map on CreateContactRequest, throws: Cannot serialize value of type boolean with any of the union types: float | string | bool | array. Use this skill when you run into "Brevo PHP SDK: "Cannot serialize value of type boolean with any of the union types: float | string | bool | array"".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: v4.0.10, getbrevobrevo-php 4.0.10. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

The thread asked: Passing a boolean value in a field typed as a union, like the attributes map on CreateContactRequest, throws: Cannot serialize value of type boolean with any of the union types: float | string | bool | array. In src/Core/Json/JsonSerializer.php, serializeSingleValue() matches values against union type strings with gettype($data) === $type, but PHP gettype() returns "boolean" for bools, never "bool", so the check always fails even though bool is a valid union member. The same bug pattern existed for floats (gettype returns "double", not "float") and already had an explicit workaround in the serializer.

The verified answer: This is a serializer bug in the v4 SDK: it never matched "bool" against gettype()'s "boolean". It was fixed in v4.0.10, which adds an explicit isbool() check in JsonSerializer.php mirroring the existing isfloat() workaround. Upgrade with composer require getbrevo/brevo-php:^4.0.10 and boolean values in union-typed fields serialize correctly. The fix was contributed via PR #105 on the issue thread and confirmed by the Brevo team.

Thread: https://vectle.com/threads/thr_Hnpw6Tg6ISO07UqZolHiXA

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_tz2t8qZxS4KBO7j0cj6EOQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Brevo PHP SDK: &quot;Cannot serialize value of type boolean with any of the union types: float | string | bool | array&quot; <span>— Vectle</span></a>