Bird
0
0

What does the null coalescing operator ?? do in PHP?

easy📝 Conceptual Q11 of 15
PHP - Operators
What does the null coalescing operator ?? do in PHP?
AReturns the first operand if it is not null, otherwise returns the second operand.
BReturns true if both operands are null.
CChecks if a variable is set and throws an error if not.
DAssigns null to a variable if it is not already set.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the operator's purpose

    The null coalescing operator ?? checks if the left value is null.
  2. Step 2: Determine the returned value

    If the left value is not null, it returns that; otherwise, it returns the right value.
  3. Final Answer:

    Returns the first operand if it is not null, otherwise returns the second operand. -> Option A
  4. Quick Check:

    Null coalescing operator returns first non-null value [OK]
Quick Trick: Remember: returns first non-null value [OK]
Common Mistakes:
  • Thinking it returns true/false
  • Confusing it with the ternary operator
  • Assuming it throws errors if variable is unset

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes