Linked Questions

551 votes
3 answers
377k views

I was diving into Symfony framework (version 4) code and found this piece of code: $env = $_SERVER['APP_ENV'] ?? 'dev'; I'm not sure what this actually does but I imagine that it expands to something ...
elkolotfi's user avatar
  • 6,410
-2 votes
1 answer
1k views

I still don't understand how to read this type checking with symbols ?? and only single ? and what's the difference. When i want to check the value of data, for an example i try this code: //using ...
chiper4's user avatar
  • 301
0 votes
2 answers
455 views

I have this kind of test again, and again, and I feel like there is a more elegant way to do it. (isset($country['capital'])) ? $country['capital'] : null Can you help me?
Juliatzin's user avatar
  • 19.9k
3 votes
0 answers
1k views

What is the difference between null coalesce operator and elvis? $a = null; echo $a ?: 'default1'; echo $a ?? 'default2'; It looks to me as they are doing the same job. However there must be ...
Jan Tajovsky's user avatar
  • 1,241
-1 votes
1 answer
494 views

How can I use Null coalescing ?? operator of PHP inside of an if statement with Laravel Eloquents to check an object exists or not? Currently, it is showing this error: SQLSTATE[42S22]: Column not ...
Sunwarul Islam's user avatar
1 vote
2 answers
277 views

I am working on an admin panel for my website that will change website settings. Everything works the way it's supposed to, except for the number of PHP warnings I get when a submit some values. I get ...
user avatar
0 votes
2 answers
100 views

How come I can use echo like this: <?php echo false ? 'yes' : 'no'; ?> //no But can't use it like this <?php echo false ?? 'yes'; ?> //nothing output
panthro's user avatar
  • 24.2k
-2 votes
2 answers
129 views

$serial = ($_SERVER['SSL_CLIENT_M_SERIAL'] ?? false); It looks like a bit like a ternary. But for that I would have expected: $serial = $_SERVER['SSL_CLIENT_M_SERIAL'] ? $_SERVER['...
Techbot's user avatar
0 votes
0 answers
44 views

I just cannot figure what is going wrong so I am asking for help. This is my statement: $fs_ski_resorts_data[$i]['fs_ski_resort_aa_zoom'] = get_field('fs_ski_resort_data_fs_aa_zoom') ?: ...
spreaderman's user avatar
  • 1,116
0 votes
0 answers
34 views

I recently read some PHP code and I've seen two operators : A ?? B operator which seems to mean take A if A is not null else take B A ?: B operator this one is the a shortcut for the ternary operator ...
Xiidref's user avatar
  • 1,531
0 votes
0 answers
23 views

I know there are countless articles out there to read about php ternary operators, however, I have read a bunch but cannot get it to work. This is my code without ternary operators: if ( get_field(...
spreaderman's user avatar
  • 1,116
63 votes
9 answers
35k views

I just found that this will work: echo $value , " continue"; but this does not: return $value , " continue"; While . works instead of , in both the echo and return statements. ...
omg's user avatar
  • 141k
36 votes
10 answers
46k views

I've been programming in PHP for years now, but I've never learned how to use any shorthand. I come across it from time to time in code and have a hard time reading it, so I'd like to learn the ...
James Simpson's user avatar
40 votes
4 answers
31k views

Is there any way to write the following statement using some kind of safe navigation operator? echo $data->getMyObject() != null ? $data->getMyObject()->getName() : ''; So that it looks like ...
Dennis's user avatar
  • 1,176
31 votes
1 answer
20k views

Something I'm not exactly clear on, how does ??, ?:, and ??= differ in PHP? I know ??= was only added in PHP7.4. I also know that ?? is for checking null values, but ?: also seems to check for null ...
QuestionMark's user avatar

15 30 50 per page