Category: PHP

If you’ve ever done OOP in PHP you are fully aware of the __construct method and the role it plays in setting up class properties, among other tasks. But have you ever given any thought on using the opposite of this function: the __destruct method? Were you aware that such a function existed?

The __destruct method was pivotal in achieving this, see the gist below: This resulted in the following file: For illustration, I’ve gone ahead and created the necessary table in my database.

There are mitigation techniques that could be used to reduce the chances of this spiraling out of control, and assuming those are implemented, I believe this provides a pretty elegant way of ensuring that any script or process inheriting this __destruct implementation always denotes when it was completed.
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