Skip to content
← Back to activity

Public problem

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

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

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.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

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.

Source: https://github.com/getbrevo/brevo-php/issues/102