Bird
0
0

Consider this PHP code snippet:

medium📝 Debug Q14 of 15
PHP - Superglobals and Web Context
Consider this PHP code snippet:
<?php
echo 'User ID: ' . $_GET['user_id'];
?>
What is the main problem if the URL does not include user_id parameter?
AIt will print 'User ID: ' with no value.
BIt will cause a Notice about undefined index.
CIt will cause a fatal error and stop the script.
DIt will automatically assign a default value.
Step-by-Step Solution
Solution:
  1. Step 1: Understand accessing missing $_GET keys

    Accessing $_GET['user_id'] when it is not set triggers a PHP Notice about undefined index.
  2. Step 2: Differentiate error types

    This is not a fatal error, so the script continues, but a warning appears. No default value is assigned automatically.
  3. Final Answer:

    It will cause a Notice about undefined index. -> Option B
  4. Quick Check:

    Missing $_GET key triggers Notice [OK]
Quick Trick: Check if parameter exists before using $_GET['key'] [OK]
Common Mistakes:
  • Assuming no error if parameter missing
  • Thinking it causes fatal error
  • Expecting automatic default values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes