Source: stitcher.io

PHP 8: before and after

Category: PHP

If you enjoy reading my blog, you could consider supporting me on Patreon. You might know that I've been working on event sourced systems lately, and I can tell you: there's lots of event configuration to do.

When I'd write this in PHP 7.4: I'll now be able to write: If you read my blog, you know I wrote quite a bit about the use of PHP's type system combined with data transfer objects. Naturally, I use lots of DTOs in my own code, so you can image how happy I am, being able to rewrite this: As this: Note the use of both constructor property promotion, as well as named arguments.

Before PHP 8, you couldn't use throw in an expression, meaning you'd have to do explicit checks like so: In PHP 8, throw has become an expression, meaning you can use it like so: If you're familiar with the null coalescing operator you're already familiar with its shortcomings: it doesn't work on method calls.
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