Bird
0
0

Identify the error in this PHP code snippet:

medium📝 Debug Q6 of 15
PHP - File Handling
Identify the error in this PHP code snippet:
$fp = fopen('file.txt', 'r');
$content = fread($fp);
echo $content;
Afopen() mode should be 'w' not 'r'
BMissing length parameter in fread()
Cfread() cannot read from file pointer
Decho cannot output file content
Step-by-Step Solution
Solution:
  1. Step 1: Check fread() function signature

    fread() requires two parameters: file pointer and length to read.
  2. Step 2: Identify missing parameter

    The code calls fread($fp) missing the length parameter, causing an error.
  3. Final Answer:

    Missing length parameter in fread() -> Option B
  4. Quick Check:

    fread() needs length parameter [OK]
Quick Trick: Always provide length to fread() [OK]
Common Mistakes:
  • Omitting length argument in fread()
  • Using wrong fopen() mode for reading
  • Assuming fread() reads whole file without length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes