What does double question mark operator mean in PHP

0 votes

 This piece of code:

$env = $_SERVER['APP_ENV'] ?? 'dev';

I'm not pretty sure what this actually does but I imagine that it expands to something like:

$env = $_SERVER['APP_ENV'] != null ? $_SERVER['APP_ENV'] : 'dev';

Or maybe:

$env = isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : 'dev';

Can anyone help me out wuth this?

Apr 2, 2020 in PHP by kartik
• 37,500 points
4,813 views

1 answer to this question.

0 votes

Hello,

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:

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

Thank You!!

answered Apr 2, 2020 by Niroj
• 82,740 points

Related Questions In PHP

0 votes
0 answers

What Does 6k views mean and how can I format the number in PHP?

What does "6k views" mean and how ...READ MORE

Jun 2 in PHP by Kichu
• 19,040 points
30 views
0 votes
0 answers

What does the variable $this mean in PHP?

Can someone please explain how the variable ...READ MORE

Jun 11 in PHP by narikkadan
• 11,280 points
15 views
0 votes
0 answers

What does this mean in PHP: -> or =>

Possible duplicate: where we use object operator “->” ...READ MORE

Jun 18 in PHP by narikkadan
• 11,280 points
16 views
0 votes
0 answers

What is meaning of tilde(~) symbol mean in the context of this PHP documentation page?

Please explain the significance of the tilde() ...READ MORE

Aug 5 in PHP by Kithuzzz
• 4,480 points
11 views
0 votes
1 answer

Why it is necessary to refresh CSRF token per form request?

Hello, Generating a new CSRF token for each ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,740 points
2,859 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,740 points
417 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,740 points
1,326 views
0 votes
1 answer

What are the differences between mysqli_connect and mysqli_pconnect?

Hello, mysqli_pconnect() function is used for making a persistence ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,740 points
2,129 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,740 points
1,492 views
0 votes
1 answer

What is type casting and type juggling in php?

Hey, The way by which PHP can assign ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,740 points
1,732 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP