1. Home
  2. Computer Science MCQs
  3. PHP
  4. In PHP 7+, what does $name = $_GET['name'] ?? 'Guest'; do?

Added 2 Nov 2026

In PHP 7+, what does $name = $_GET['name'] ?? 'Guest'; do?

  1. Throws an error when the key is missing
  2. Compares the two values for equality
  3. Always overwrites the value with 'Guest'
  4. 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

MCQSEXAM

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

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs