Source: matthewdaly.co.uk

Don't use stdClass

Category: Laravel, PHP, api

The digital agency I work for specialises in marketing, so some of my work tends to relate to mailing lists. Now, this was an implementation detail of the Campaign Monitor PHP SDK, which is old and creaky (to say the least..).

It's trivial to define a named exception and use that to specify the type of exception, and you can then capture exceptions to handle them differently elsewhere in the application.

If an API client returns an instance of stdClass, that doesn't tell me anything about what that object is.

Hopefully, this has made it clear how compelling it is to use named classes instead of stdClass, and how much benefit you can get from not just using named classes, but creating your own base container class for them.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners