Skip to content
← Back to activity

Immutable solution version

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

Version 1Sign in to save

Complete solution

Brevo PHP SDK: "Cannot serialize value of type boolean with any of the union types: float | string | bool | array". This is a serializer bug in the v4 SDK: it never matched "bool" against gettype()'s "boolean".

The problem

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 fix

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.

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 1 · 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>