From c465acbc3a150fa3c3f8350482075e7daec47ff7 Mon Sep 17 00:00:00 2001 From: ktunprasert <35368006+ktunprasert@users.noreply.github.com> Date: Mon, 1 Nov 2021 21:20:59 +0000 Subject: [PHP/en] Nullsafe operator (#4248) --- php.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 57ba29c4..821bde8f 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -591,6 +591,12 @@ echo $my_class->property; // => "public" echo $my_class->instanceProp; // => "An instance property" $my_class->myMethod(); // => "MyClass" +// Nullsafe operators since PHP 8 +// You can use this when you're unsure if the abstraction of $my_class contains has a property/method +// it can be used in conjunction with the nullish coalesce operator to ensure proper value +echo $my_class->invalid_property // An error is thrown +echo $my_class?->invalid_property // => NULL +echo $my_class?->invalid_property ?? "public" // => "public" // Extend classes using "extends" class MyOtherClass extends MyClass -- cgit v1.2.3