Source: stitcher.io

PHP 8: the nullsafe operator

Category: PHP, PHP

If you've used the null coalescing operator in the past, you probably also noticed its shortcomings: null coalescing doesn't work on method calls. Instead you need intermediate checks, or rely on optional helpers provided by some frameworks: The nullsafe operator provides functionality similar to null coalescing, but also supports method calls. Instead of writing this: PHP 8 allows you to write this: Let's take a look at what this new operator can and cannot do!

You could do this both with the null coalescing operator and the nullsafe operator: So what's the difference?

Sometimes you could use either the null coalescing or nullsafe operator, and other times you'd need to use a specific one.
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.
Community Partners