Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q5 of 15
PHP - File Handling
What will this PHP code output?
$file = fopen('log.txt', 'a');
fwrite($file, "Test\n");
fclose($file);
echo filesize('log.txt');
AError because file is closed
B0
CSize of file including new 'Test' line
DTest
Step-by-Step Solution
Solution:
  1. Step 1: Understand append mode and fwrite

    Opening with 'a' appends "Test\n" to the file, increasing its size.
  2. Step 2: Recognize filesize after fclose

    After closing, filesize reflects the updated file size including the new content.
  3. Final Answer:

    Size of file including new 'Test' line -> Option C
  4. Quick Check:

    filesize after fclose = updated size [OK]
Quick Trick: Use 'a' mode to append and see updated filesize after fclose [OK]
Common Mistakes:
  • Expecting filesize before fclose to update
  • Confusing append with overwrite
  • Thinking echo prints file content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes