Bird
0
0

You want to show all errors except deprecated warnings during development but hide all errors on the live site. Which code setup achieves this best?

hard📝 Application Q15 of 15
PHP - Error and Exception Handling
You want to show all errors except deprecated warnings during development but hide all errors on the live site. Which code setup achieves this best?
A<code>error_reporting(E_ALL); ini_set('display_errors', 1);</code>
B<code>error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', 0);</code>
C<code>if (ENV == 'dev') { error_reporting(E_ALL & ~E_DEPRECATED); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); }</code>
D<code>if (ENV == 'prod') { error_reporting(E_ALL); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); }</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment-based error settings

    During development (dev), show all errors except deprecated; on live (prod), hide all errors.
  2. Step 2: Analyze each option

    if (ENV == 'dev') { error_reporting(E_ALL & ~E_DEPRECATED); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); } correctly uses error_reporting with exclusion and display_errors on dev, off on live.
  3. Final Answer:

    if (ENV == 'dev') { error_reporting(E_ALL & ~E_DEPRECATED); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); } -> Option C
  4. Quick Check:

    Dev shows errors except deprecated; live hides all [OK]
Quick Trick: Use environment check to toggle error reporting and display [OK]
Common Mistakes:
  • Showing errors on live site
  • Not excluding deprecated warnings during dev
  • Confusing environment variable names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes