It's the "null coalescing operator", added in php 7.0. The definition of how it works is:

It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.

So it's actually just isset() in a handy operator.

Those two are equivalent1:

bar ?? 'something';
$foo = isset(bar : 'something';

Documentation: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce

In the list of new PHP7 features: http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

And original RFC https://wiki.php.net/rfc/isset_ternary


EDIT: As this answer gets a lot of views, little clarification:

1There is a difference: In case of ??, the first expression is evaluated only once, as opposed to ? :, where the expression is first evaluated in the condition section, then the second time in the "answer" section.

Answer from michalhosna on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_operators.asp
PHP Operators
Loops While Loop Do While Loop For Loop Foreach Loop Break Statement Continue Statement PHP Functions PHP Arrays ยท Arrays Indexed Arrays Associative Arrays Create Arrays Access Array Items Update Array Items Add Array Items Remove Array Items Sorting Arrays Multidimensional Arrays Array Functions PHP Superglobals
Top answer
1 of 3
668

It's the "null coalescing operator", added in php 7.0. The definition of how it works is:

It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.

So it's actually just isset() in a handy operator.

Those two are equivalent1:

bar ?? 'something';
$foo = isset(bar : 'something';

Documentation: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce

In the list of new PHP7 features: http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

And original RFC https://wiki.php.net/rfc/isset_ternary


EDIT: As this answer gets a lot of views, little clarification:

1There is a difference: In case of ??, the first expression is evaluated only once, as opposed to ? :, where the expression is first evaluated in the condition section, then the second time in the "answer" section.

2 of 3
55
$myVar = $someVar ?? 42;

Is equivalent to :

$myVar = isset($someVar) ? $someVar : 42;

For constants, the behaviour is the same when using a constant that already exists :

define("FOO", "bar");
define("BAR", null);

$MyVar = FOO ?? "42";
$MyVar2 = BAR ?? "42";

echo $MyVar . PHP_EOL;  // bar
echo $MyVar2 . PHP_EOL; // 42

However, for constants that don't exist, this is different :

$MyVar3 = IDONTEXIST ?? "42"; // Raises a warning
echo $MyVar3 . PHP_EOL;       // IDONTEXIST

Warning: Use of undefined constant IDONTEXIST - assumed 'IDONTEXIST' (this will throw an Error in a future version of PHP)

Php will convert the non-existing constant to a string.

You can use constant("ConstantName") that returns the value of the constant or null if the constant doesn't exist, but it will still raise a warning. You can prepended the function with the error control operator @ to ignore the warning message :

$myVar = @constant("IDONTEXIST") ?? "42"; // No warning displayed anymore
echo $myVar . PHP_EOL; // 42
Discussions

Understanding the Use of the "..." Operator in PHP
Wow, I somehow missed its announcement. So yes, looks like it's a First class callable syntax . Feels a bit confusing at first, but I think I can get used to it. Regarding the code, $this->initial(...) is the way to create a closure from a regular method. The old way to do the same would be array_map([$this,'initial'], explode(' ', $name)); More on reddit.com
๐ŸŒ r/PHP
3
12
September 20, 2023
What is the difference between ' ' and " " in PHP ? and when, where should I use it
Beau Delfosse is having issues with: If you know, could you maybe give me some tags where I can use them in ? More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
3
January 27, 2016
?: operator (the 'Elvis operator') in PHP - Stack Overflow
I saw this today in some PHP code: $items = $items ?: $this->_handle->result('next', $this->_result, $this); I'm not familiar with the ?: operator being used here. It looks like a ternary More on stackoverflow.com
๐ŸŒ stackoverflow.com
php equivalent of mysql "IN" operator? - Stack Overflow
I haven't coded in PHP in awhile and I'm not having luck with Googleing this basic question. If I want to do something like: if ($x == $a || $x == $b || $x == $foo || $x == $bar) { //whatever Wha... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ language.operators.php
PHP: Operators - Manual
Note: If you write following code, you would need "()" to get expected value. <?php $bar = true; $str = "TEST". ($bar ? 'true' : 'false') ."TEST"; ?> Without "(" and ")" you will get only "true" in $str.
๐ŸŒ
Reddit
reddit.com โ€บ r/php โ€บ understanding the use of the "..." operator in php
r/PHP on Reddit: Understanding the Use of the "..." Operator in PHP
September 20, 2023 -

I recently came across a PHP code snippet that uses the "..." operator in a context that I'm not very familiar with. The code includes a method called initials that uses the "..." operator in an array_map function. Here's the code snippet for reference:

class HighSchoolSweetheart
{
    public function initial(string $name): string
    {
        return strtoupper($this->firstLetter($name)) . '.';
    }
    
    public function initials(string $name): string
    {
        $initials = array_map($this->initial(...), explode(' ', $name));
    
        return implode(' ', $initials);
    }
}

I understand that the "..." operator is often used for argument unpacking in PHP and that array_map is used to apply a callback function ($this->initial(...)) to each element of an array created by explode(' ', $name). However, I'm not entirely clear on how the splat operator "..." functions in this context. Can someone explain its role in this code and how it affects the initial method? Thanks!

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ php-operators
PHP Operators - GeeksforGeeks
June 14, 2025 - In PHP, operators are special symbols used to perform operations on variables and values. Operators help you perform a variety of tasks, such as mathematical calculations, string manipulations, logical comparisons, and more.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ func_array_in_array.asp
PHP in_array() Function
Loops While Loop Do While Loop For Loop Foreach Loop Break Statement Continue Statement PHP Functions PHP Arrays ยท Arrays Indexed Arrays Associative Arrays Create Arrays Access Array Items Update Array Items Add Array Items Remove Array Items Sorting Arrays Multidimensional Arrays Array Functions PHP Superglobals
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_numbers.asp
PHP Numbers
A float is a number with a decimal point or a number in exponential form: 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats. ... The float data type can commonly store a value up to 1.7976931348623E+308 (platform dependent), and have a maximum precision of 14 digits. PHP has the following predefined constants for floats (from PHP 7.2):
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_variables.asp
PHP Variables
PHP Date and Time PHP Include PHP File Handling PHP File Open/Read PHP File Create/Write PHP File Upload PHP Cookies PHP Sessions PHP Filters PHP Filters Advanced PHP Callback Functions PHP JSON PHP Exceptions
๐ŸŒ
Learn X in Y Minutes
learnxinyminutes.com โ€บ php
Learn PHP in Y Minutes
// Once you assign a value, PHP will create the variable with the right type. // Boolean values are case-insensitive $boolean = true; // or TRUE or True $boolean = FALSE; // or false or False // Integers $int1 = 12; // => 12 $int2 = -12; // => -12 $int3 = 012; // => 10 (a leading 0 denotes an octal number) $int4 = 0x0F; // => 15 (a leading 0x denotes a hex literal) // Binary integer literals are available since PHP 5.4.0.
๐ŸŒ
Codecademy
codecademy.com โ€บ learn โ€บ learn-php โ€บ modules โ€บ conditionals-logic-php โ€บ cheatsheet
Learn PHP: Conditionals and Logic in PHP Cheatsheet | Codecademy
PHP values within a condition will always be evaluated to TRUE or FALSE. Values that will evaluate to TRUE are known as truthy and values that evaluate to FALSE are known as falsy. ... All other values are truthy. ... In PHP, the ternary operator allows for a compact syntax in the case of binary (if/else) decisions.