Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Error and Exception Handling
What will be the output of this PHP code?
function test() {
  try {
    echo "Try ";
    return;
  } finally {
    echo "Finally ";
  }
  echo "After";
}
test();
ATry After Finally
BTry Finally
CTry
DFinally Try
Step-by-Step Solution
Solution:
  1. Step 1: Trace try block

    Prints "Try ", then return is called.
  2. Step 2: finally block runs before return

    Prints "Finally ".
  3. Step 3: Code after finally is skipped due to return

    "After" is not printed.
  4. Final Answer:

    Try Finally -> Option B
  5. Quick Check:

    finally runs before return completes [OK]
Quick Trick: finally runs even if try returns early [OK]
Common Mistakes:
  • Expecting code after finally to run
  • Thinking finally runs after return completes
  • Mixing output order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes