Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q6 of 15
PHP - Superglobals and Web Context
What is wrong with this code snippet?
if ($_REQUEST['submit']) { echo 'Form submitted'; }
AThe echo statement is missing parentheses
BThe syntax for accessing $_REQUEST is incorrect
C$_REQUEST cannot be used in if conditions
DIt may cause an undefined index notice if 'submit' is not set
Step-by-Step Solution
Solution:
  1. Step 1: Check array access safety

    Accessing $_REQUEST['submit'] without checking if it exists can cause a PHP notice if 'submit' is not set.
  2. Step 2: Identify correct fix

    Use isset($_REQUEST['submit']) to avoid the notice.
  3. Final Answer:

    It may cause an undefined index notice if 'submit' is not set -> Option D
  4. Quick Check:

    Always check if key exists before accessing $_REQUEST [OK]
Quick Trick: Check isset() before accessing $_REQUEST keys [OK]
Common Mistakes:
  • Ignoring undefined index notices
  • Assuming $_REQUEST keys always exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes