Bird
0
0

Find the problem in this PHP script that tries to keep a counter across runs:

medium📝 Debug Q7 of 15
PHP - Request Lifecycle
Find the problem in this PHP script that tries to keep a counter across runs:
<?php
$counter = 0;
$counter++;
echo $counter;
?>
AMissing session_start() to use sessions
BEcho statement syntax error
CIncorrect increment operator used
DVariables reset each run, so counter never increases beyond 1
Step-by-Step Solution
Solution:
  1. Step 1: Analyze variable reset behavior

    $counter is set to 0 every run, so increment always starts from zero.
  2. Step 2: Understand why counter does not persist

    Without persistent storage like sessions, variables reset and counter never grows.
  3. Final Answer:

    Variables reset each run, so counter never increases beyond 1 -> Option D
  4. Quick Check:

    Variables reset each run = counter resets [OK]
Quick Trick: Variables reset each run unless stored in session or file [OK]
Common Mistakes:
  • Expecting variables to persist automatically
  • Confusing increment operator usage
  • Ignoring need for session or file storage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes