diff options
author | ktunprasert <35368006+ktunprasert@users.noreply.github.com> | 2021-11-01 21:20:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 22:20:59 +0100 |
commit | c465acbc3a150fa3c3f8350482075e7daec47ff7 (patch) | |
tree | ceafc401f4ca7b129dc7dffafc48e278cfb34664 | |
parent | 8af43d446ec2afb9d5dbb4a978a976e682399a4d (diff) |
[PHP/en] Nullsafe operator (#4248)
-rw-r--r-- | php.html.markdown | 6 |
1 files changed, 6 insertions, 0 deletions
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 |