Skip to content

Empty arrays needs to be null values #30

@xolf

Description

@xolf

I've discovered that empty arrays are not supported by this library for array values. Instead, an explicit null value is expected to represent an array with no elements. Otherwise, a get_class(): Argument #1 ($object) must be of type object, array given exception will be thrown.

From my perspective, this behavior feels somewhat unintuitive, as it requires rechecking and explicitly setting values to null when mapping data from internal objects to Apideck objects, instead of simply accepting empty arrays.

For instance, the following code:

$lead->emails = $my_lead->emails->map(fn ($email) => new Email(email: $email))->toArray();

needs to be rewritten as:

$lead->emails = $my_lead->emails->map(fn ($email) => new Email(email: $email))->toArray();
if (count($lead->emails) == 0) $lead->emails = null;

I would suggest and prefer that the library supports empty arrays alongside null values for array elements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions