PHP 8 – Nullsafe operator

The operator nullsafe allows a developer to eliminate the null check for each property before going onto the next chain of the property or method.

It is very common to only want to call a method or fetch a property on the result of an expression if it is not null.

For example, to access user address street details, without null safe Operator you need to have an intermediate check as shown below.

Here the example with nulsafe operator:

see you can avoid intermediate checks with this operator.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
DMCA.com Protection Status
0
Would love your thoughts, please comment.x
()
x