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. Answer from ClosetLink on reddit.com
🌐
PHP
php.net › manual › en › migration70.new-features.php
PHP: New features - Manual
The null coalescing operator (??) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction with isset().
🌐
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.
Discussions

php 7.4 - What is null coalescing assignment ??= operator in PHP 7.4 - Stack Overflow
I've just seen a video about upcoming PHP 7.4 features and saw new ??= operator. I already know the ?? operator. How's this different? ... Coalesce equal or ??=operator is an assignment operator. If the left parameter is null, assigns the value of the right parameter to the left one. More on stackoverflow.com
🌐 stackoverflow.com
Here's a quick tip: you can use the null coalescing assignment operator for easy memoisation in PHP 7.4
That's right, but just for the record, this was the most concise version before 7.4: return $this->cache[$input] = $this->cache[$input] ?? $this->resolve($input); More on reddit.com
🌐 r/PHP
39
134
October 21, 2019
Null coalescing assignment operator ??= is now confirmed for PHP 7.4
Am I the only one that thinks these aren't _awesome_ features? --- IMO it doesn't improve readability. I wanna bet $1 that you'll see code like this: More on reddit.com
🌐 r/PHP
56
120
January 22, 2019
Does PHP 7.2 and up support null coalescing operators that nullify exceptions?
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. More on reddit.com
🌐 r/PHPhelp
9
1
November 4, 2021
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....
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. Answer from ClosetLink on reddit.com
🌐
Wikipedia
en.wikipedia.org › wiki › Null_coalescing_operator
Null coalescing operator - Wikipedia
October 31, 2025 - Version 7.4 of PHP introduced the Null Coalescing Assignment Operator with the ??= syntax:
Find elsewhere
🌐
Educative
educative.io › answers › what-is-a-null-coalescing-operator-in-php
What is a null coalescing operator in PHP?
The null coalescing operator is a binary operator which was introduced in PHP 7. It allows the programmers to shorten the code for checking variable values using isset function in conjunction with ternary operator or if-else statement.
🌐
FlatCoding
flatcoding.com › home › php null coalescing operator: handling null values
PHP Null Coalescing Operator: Handling Null Values - FlatCoding
June 30, 2025 - The null coalescing operator (??) was added in PHP 7. It checks if a variable is set and not null. If it is, it uses that value.
🌐
Kilukru
kilukru.dev › home › kilukru – actualités techno – web – internet › opérateur coalescent null ou null coalescing operator (??)
Opérateur coalescent null ou Null Coalescing Operator (??) - Kilukru par Alfred Dagenais
December 21, 2021 - Null Coalescing Operator ?? est une nouvelle fonctionnalité de PHP 7. Il est généralement utilisé pour vérifier si une variable a une valeur. Il sera plus facile pour vous de comprendre si vous avez déjà utilisé l’opérateur ternaire ...
🌐
Medium
medium.com › @prevailexcellent › mastering-null-safety-in-php-8-a-comprehensive-guide-to-using-the-null-safe-operator-47835ba1140b
Mastering Null Safety in PHP 8: A Comprehensive Guide to Using the Null Safe Operator | by Chimeremze Prevail Ejimadu | Medium
June 14, 2023 - It’s important to note that the null safe operator short-circuits the expression as soon as it encounters a null value. This means that subsequent method calls or property accesses in the chain will not be executed if any of the preceding objects are null. In PHP, the null coalescing operator ...
🌐
Stitcher
stitcher.io › blog › php-8-nullsafe-operator
PHP 8: the null safe operator | Stitcher.io
November 17, 2020 - The null safe operator allows you to safely call methods and properties on nullables on PHP 8.
🌐
WordPress
wordpress.org › support › topic › null-coalescing-operator-breaks-php-5-compatibility-since-14-0
Null coalescing operator breaks PHP 5 compatibility since 14.0 | WordPress.org
May 13, 2023 - Forums / Plugin: WP Statistics – Simple, privacy-friendly Google Analytics alternative / Null coalescing operator breaks PHP 5 compatibility since 14.0 ... The code has compatibility issues with PHP 5.6 since version 14.0. You need to make ...
🌐
PHP.Watch
php.watch › versions › 8.0 › null-safe-operator
Null-safe operator - PHP 8.0 • PHP.Watch
Null-safe operator is a new syntax in PHP 8.0, that provides optional chaining feature to PHP.
🌐
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 - PHP7 came with syntactic flavourings we all have been savouring ever since its release - One of which is the null-coalescing operator.
🌐
Stitcher
stitcher.io › blog › shorthand-comparisons-in-php
Shorthand comparisons in PHP | Stitcher.io
Furthermore, as PHP 7.4, the use of chained ternaries without brackets is deprecated. ... Did you take a look at the types comparison table earlier? The null coalescing operator is available since PHP 7.0.
🌐
PHP.Watch
php.watch › articles › php-ternary-and-coalescing
Ternary and Ternary Coalescing Operator in PHP • PHP.Watch
May 27, 2020 - Null Coalescing operator can be be further reduced in PHP 7.4, with Null Coalescing Assignment operator .
🌐
YouTube
youtube.com › laravel daily
PHP Null Coalescing Operators: Do You Use Them? - YouTube
A quick video about the PHP syntax which I don't see used enough in the wild.More Laravel tips: https://github.com/LaravelDaily/laravel-tips- - - - -Support ...
Published   June 30, 2022
Views   10K
🌐
Benjamin Crozat
benjamincrozat.com › home › blog › php › php's double question mark, or the null coalescing operator
PHP's double question mark, or the null coalescing operator
September 28, 2025 - The null coalescing operator, or double question mark, was introduced in PHP 7.0 and helps you write cleaner, more readable code.