In PHP 7+, what does $name = $_GET['name'] ?? 'Guest'; do?
A
Throws an error when the key is missing
B
Compares the two values for equality
C
Always overwrites the value with 'Guest'
D
Uses 'Guest' if the key is missing or null
Correct answer
Correct answer
D. Uses 'Guest' if the key is missing or null
16 views
⚔️
Challenge a friend on PHP
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
The null coalescing operator (??) returns the left operand if it exists and is not null, otherwise the right. It replaces verbose isset() ternaries without raising notices.
Reference
Asked in: NTS, PHP Developer Interviews
Doubts & discussionNot sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ What does array_map(fn($x) => $x * 2, [1, 2, 3]) return? Next MCQ › How does PHP 8's match expression differ from a switch statement?