Bird
0
0

What happens when you open a file with mode "w" in PHP?

easy📝 Conceptual Q2 of 15
PHP - File Handling
What happens when you open a file with mode "w" in PHP?
AThe file is opened for reading only
BThe file is created if it doesn't exist and truncated if it does
CThe file is opened for appending data
DThe file is locked and cannot be accessed
Step-by-Step Solution
Solution:
  1. Step 1: Understand "w" mode behavior

    "w" mode opens a file for writing, creates it if missing, and clears existing content.
  2. Step 2: Check other options

    "w" does not open for reading or appending, nor does it lock the file exclusively.
  3. Final Answer:

    "w" creates or truncates file for writing -> Option B
  4. Quick Check:

    Write mode "w" = create or clear file [OK]
Quick Trick: "w" clears file or creates new for writing [OK]
Common Mistakes:
  • Thinking "w" appends instead of truncates
  • Assuming "w" opens for reading
  • Believing "w" locks file automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes