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 From bba9f7df211d63293e2a957872d156a0a6dfcd48 Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Sat, 10 Dec 2022 12:05:34 -0300 Subject: Fixes typos in many different English articles Signed-off-by: Marcel Ribeiro-Dantas --- php.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 821bde8f..61f1c00c 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -443,7 +443,7 @@ $bar('C'); // Prints "A - B - C" // You can call named functions using strings $function_name = 'add'; echo $function_name(1, 2); // => 3 -// Useful for programatically determining which function to run. +// Useful for programmatically determining which function to run. // Or, use call_user_func(callable $callback [, $parameter [, ... ]]); -- cgit v1.2.3 From cc6c14ba99fd62a58d6cef67a23a2262a5353386 Mon Sep 17 00:00:00 2001 From: Tamnac <49466795+Tamnac@users.noreply.github.com> Date: Sat, 22 Jul 2023 21:01:36 -0700 Subject: add more information for strings --- php.html.markdown | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 61f1c00c..1ef52f68 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -92,9 +92,10 @@ $escaped = "This contains a \t tab character."; $unescaped = 'This just contains a slash and a t: \t'; // Enclose a variable in curly braces if needed -$apples = "I have {$number} apples to eat."; -$oranges = "I have ${number} oranges to eat."; -$money = "I have $${number} in the bank."; +$number = 23; +$apples = "I have {$number} apples to eat."; // => I have 23 apples to eat. +$oranges = "I have ${number} oranges to eat."; // => I have 23 oranges to eat. +$money = "I have $${number} in the bank."; // => I have $23 in the bank. // Since PHP 5.3, nowdocs can be used for uninterpolated multi-liners $nowdoc = <<<'END' @@ -109,7 +110,7 @@ $sgl_quotes END; // String concatenation is done with . -echo 'This string ' . 'is concatenated'; +echo 'This string ' . 'is concatenated'; // Returns 'This string is concatenated' // Strings can be passed in as parameters to echo echo 'Multiple', 'Parameters', 'Valid'; // Returns 'MultipleParametersValid' -- cgit v1.2.3