Bird
0
0

Why does PHP require the closing identifier of heredoc/nowdoc to be on a new line without indentation or trailing spaces?

hard📝 Conceptual Q10 of 15
PHP - Output and String Handling
Why does PHP require the closing identifier of heredoc/nowdoc to be on a new line without indentation or trailing spaces?
ATo allow comments inside the string
BTo allow variable parsing inside the string
CTo enable multi-line string support
DTo avoid ambiguity in parsing the string end
Step-by-Step Solution
Solution:
  1. Step 1: Understand parsing rules

    PHP needs a clear marker to know where the string ends.
  2. Step 2: Reason about indentation

    If the closing identifier is indented or has trailing spaces, PHP cannot reliably detect the string end.
  3. Final Answer:

    To avoid ambiguity in parsing the string end -> Option D
  4. Quick Check:

    Closing identifier placement = parsing clarity [OK]
Quick Trick: Closing identifier must be exact to mark string end [OK]
Common Mistakes:
  • Thinking indentation affects variable parsing
  • Assuming multi-line support depends on closing line

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes