The correct answer above from @mrks can be shortened to:

$params['phone'] ??= 'default';

RFC: Null coalesce equal operator

Answer from Dmitry Bordun on Stack Overflow
🌐
PHP
php.net › manual › en › migration70.new-features.php
PHP: New features - Manual
<?php function arraysSum(array ... declarations. reference. The null coalescing operator (??) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction with isset()....
🌐
PHP Tutorial
phptutorial.net › home › php tutorial › php null coalescing operator
PHP Null Coalescing Operator
June 25, 2021 - <?php $name = $_POST['name'] ?? 'John';Code language: PHP (php) In this example, the ?? is the null coalescing operator. It accepts two operands. If the first operand is null or doesn’t exist, the null coalescing operator returns the second operand. Otherwise, it returns the first one. In the above example, if the variable name doesn’t exist in the $_POST array or it is null, the ??
People also ask

What is the syntax of the null coalescing operator?
The syntax is:
$variable = $value ?? $default;
Here, $value is checked first. If it is null, $default is used instead.
🌐
flatcoding.com
flatcoding.com › home › php null coalescing operator: handling null values
PHP Null Coalescing Operator: Handling Null Values - FlatCoding
When should I use the null coalescing operator?
Use it when you want to give a default value to a variable that might be null or not set. It is common with user input, settings, arrays, or function results.
🌐
flatcoding.com
flatcoding.com › home › php null coalescing operator: handling null values
PHP Null Coalescing Operator: Handling Null Values - FlatCoding
Does the null coalescing operator work with functions?
Yes. It can handle function return values that might be null. For example:
$username = getUserName() ?? 'Guest';
🌐
flatcoding.com
flatcoding.com › home › php null coalescing operator: handling null values
PHP Null Coalescing Operator: Handling Null Values - FlatCoding
🌐
Tutorialspoint
tutorialspoint.com › home › php › php null coalescing operator
PHP Null Coalescing Operator
May 26, 2007 - Let us use the ternary operator ... set"; echo "The value of x is $var"; ?> ... The Null Coalescing Operator is represented by the "??" symbol....
🌐
Markshust
markshust.com › 2017 › 08 › 25 › php-7s-null-coalesce-operator-usage-objects-and-arrays
PHP 7's null coalesce operator usage with Objects and Arrays | Mark Shust
This script executes successfully. What happens is that since $foo is not defined, null coalesce assigns the iterable the value of an empty array.
🌐
Stitcher
stitcher.io › blog › php-8-nullsafe-operator
PHP 8: the null safe operator | Stitcher.io
While you could use both operators to achieve the same result in this example, they also have specific edge cases only one of them can handle. For example, you can use the null coalescing operator in combination with array keys, while the nullsafe operator can't handle them:
🌐
DEV Community
dev.to › frknasir › php-null-safe-and-null-coalescing-operators-jg2
PHP null-safe and null-coalescing operators - DEV Community
July 6, 2021 - The null-safe operator supports method while the null-coalescing operator doesn't. The null-coalescing operator supports array while the null-safe operator doesn't. Tagged with php, 100daysofcode, codenewbie, webdev.
🌐
FlatCoding
flatcoding.com › home › php null coalescing operator: handling null values
PHP Null Coalescing Operator: Handling Null Values - FlatCoding
June 30, 2025 - In this example, we try to get the age value from the $person array. But this key has a value of null. By using the null coalescing operator in PHP, we can set $age to 'Unknown' instead of null.
Find elsewhere
🌐
Reddit
reddit.com › r/phphelp › does php 7.2 and up support null coalescing operators that nullify exceptions?
r/PHPhelp on Reddit: Does PHP 7.2 and up support null coalescing operators that nullify exceptions?
November 4, 2021 -

Hi,

There are really two questions - at some point in programming PHP these past 2 years I started avoiding the null coalescing operator (??), but I don’t really know why since they all use 7.2 and the docs say the operator is available starting in 7.0.

Is the null coalescing operator safe in 7.2 and up?

Will it store null if there’s an exception generated, especially indexing a nested array and trying to Index on null or undefined?

Does isset() catch exceptions and return null as well? Or will it throw an exception?

Thanks!

Top answer
1 of 7
3
I believe you have some fundamental misunderstanding of a few things. The only way to catch exceptions is with catch. Exceptions are errors, so it wouldn't make sense for the null coalescing operator—which returns some value if the left-hand value is null—to magically suppress it. It also wouldn't make sense for the null coalescing operator to assume something is null if an exception occurred. Why would it? See here . Notice how the exception basically kills everything. That's supposed to happen because it means something went wrong, not that something went null. According to the PHP docs , "the program will terminate with a fatal error" if an unhandled exception occurs. Now look here . In this case, the exception was handled and the code continued as normal. At no point does the exception stop execution, at no point is null somehow returned. It's totally unrelated. If you're getting exceptions in general, you need to be handling them because they mean an error occurred that should not have occurred. That means either A) using catch, not to suppress them, but to handle them and do whatever needs to be done (for example, displaying a pretty error message), or B) rewriting whatever portion of your code allowed the exception to be thrown in the first place such that it will never happen again. So, to answer your two questions... no, PHP 7.2 does not support null coalescing operators that "nullify" exceptions, and it never will. However, yes, null coalescing operators are safe to use.
2 of 7
1
The ternary operator is a short replacement for simple if statements like this: if ($var) { } else { } Which matches whether the result of $var is true or false, whereas the null coalescing operator tests on not NULL and is a short replacement for: if (!is_null($var)) { } else { } A common gotcha in PHP is what contributes to a NULL value. You can set a string to "", and to empty() this returns true just the same as the value not defined or set to NULL. However, isset() checks to see if the variable is set and not NULL, and "" is not NULL, so it returns true, is_null does the opposite, returning "" as false. gettype() returns a string if the variable contains "" and empty() returns true in all three cases with boolean returning false in all three cases. If you know there will be an exception use break to break out of the loop before the exception occurs. You can specify the depth of the loop you wish to break out of, so a break 2; will break out of a nested loop that consists of two loops. You can test for exceptions by putting the code you suspect will cause an exception in the try block, then return the exception from the catch block and optionally, run code after from the finally block.
🌐
PHP Delusions
phpdelusions.net › articles › null_coalescing_abuse
Do you abuse the null coalescing operator (and isset/empty as well)? - Treating PHP Delusions
if $foo = null|FooInterface then a simple ternary is sufiicient: $foo instanceof FooInterface ? 'Good' : 'Bad'; ... I sort of agree, but I am for letting programmers program. If they abuse the ?? operator to suppress error messages, then they are probably just inexperienced. I doubt that telling them not to use ?? will accelerate the learning process. I do not find experienced programmers to typically do that. I very commonly use ?? to test for array indices, e.g.
🌐
GitHub
github.com › phpstan › phpstan › issues › 4592
Null coalescing operator on multi-level array access · Issue #4592 · phpstan/phpstan
February 23, 2021 - If I apply the coalescing operator to a two-level array access ($foo[$one][$two]) where the second level is guaranteed to be set, phpstan does not take into account that the first level might be undefined. If you run phpstan on the snippet below, it will complain that $name can never be null in sayHello1().
Published   Feb 23, 2021
🌐
dailycomputerscience
dailycomputerscience.com › post › php-8-null-coalescing-operator
PHP 8 Null Coalescing Operator
October 5, 2024 - Without the null coalescing operator, ... introduced the null coalescing assignment operator (??=), which allows you to assign a value to a variable only if it is null....
🌐
Medium
frknasir.medium.com › php-null-safe-and-null-coalescing-operators-727eda4a2073
PHP null-safe and null-coalescing operators | by Faruk Nasir | Medium
April 23, 2021 - The null-safe operator supports method while the null-coalescing operator doesn’t. The null-coalescing operator supports array while the null-safe operator doesn’t.
🌐
Stitcher
stitcher.io › blog › shorthand-comparisons-in-php
Shorthand comparisons in PHP | Stitcher.io
The null coalescing operator is ... its boolean value. This makes this operator especially useful for arrays and assigning defaults when a variable is not set....
🌐
Linux Hint
linuxhint.com › null_coalescing_php
How to use PHP Null Coalescing Operator – Linux Hint
The null coalescing operator can be used with two or more variables. In this example, the operator is used to check the values of different variables. <?php //Define two variables $var1 = 'This is the first string value.'; $var3 = 'This is the third string value.'; $var4 = NULL; $var5 = 'This is the fifth string value.'; $var6 = ''; //Check the value of the variables $result1 = $var1 ??
🌐
Strangebuzz
strangebuzz.com › home › snippets › using the php null coalescing assignment operator
Using the PHP null coalescing assignment operator | Strangebuzz
*/ trait Snippet217Trait { public function snippet217(): void { $myArray = []; $myArray[ByteString::fromRandom(8)->toString()] = 'bar1'; $myArray[ByteString::fromRandom(8)->toString()] = 'bar2'; $myArray['foo'] ??= 'bar3'; var_dump($myArray); $myArray[array_key_last($myArray)] ??= 'not modified'; var_dump($myArray); // That's it! 😁 } } Run this snippet ≪ this.showUnitTest ? this.trans.hide_unit_test : this.trans.show_unit_test ≫ More on Stackoverflow Read the doc More on the web · Work with me! <?php declare(strict_types=1); namespace App\Tests\Integration\Controller\Snippets; use PHPU
🌐
CopyProgramming
copyprogramming.com › howto › using-phps-null-coalescing-operator-on-an-array
Using PHP's Null Coalescing Operator on Arrays: The Complete 2026 Guide
December 16, 2025 - The null coalescing operator continues to work exactly as expected and remains a cornerstone of defensive programming in modern PHP. While PHP 8.5 brings new array utility functions like array_first() and array_last(), the null coalescing operator remains unchanged.
🌐
Rip Tutorial
riptutorial.com › null coalescing operator (??)
PHP Tutorial => Null Coalescing Operator (??)
Null coalescing is a new operator introduced in PHP 7. This operator returns its first operand if it is set and not NULL.
🌐
EITCA
eitca.org › home › how does the null coalescing operator work in php?
How does the null coalescing operator work in PHP? - EITCA Academy
August 8, 2023 - The null coalescing operator is represented by two question marks (??). It works by evaluating the expression on the left-hand side of the operator. If this expression is not null, the operator returns its value. However, if the expression is null, the operator evaluates the expression on the ...