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.