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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners