Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>SUMMARY</strong></p> <p>The <a href="http://php.net/manual/en/errorfunc.configuration.php" rel="noreferrer">PHP Runtime Configuration Docs</a> give you some idea why:</p> <blockquote> <p>Enabling E_NOTICE during development has some benefits.</p> <p>For debugging purposes: NOTICE messages will warn you about possible bugs in your code. For example, use of unassigned values is warned. It is extremely useful to find typos and to save time for debugging.</p> <p>NOTICE messages will warn you about bad style. For example, $arr[item] is better to be written as $arr['item'] since PHP tries to treat "item" as constant. If it is not a constant, PHP assumes it is a string index for the array.</p> </blockquote> <p>Here's a more detailed explanation of each...</p> <hr> <p><strong>1. TO DETECT TYPOS</strong></p> <p>The main cause of <code>E_NOTICE</code> errors is typos.</p> <p><strong>Example - notice.php</strong></p> <pre><code>&lt;?php $username = 'joe'; // in real life this would be from $_SESSION // and then much further down in the code... if ($usernmae) { // typo, $usernmae expands to null echo "Logged in"; } else { echo "Please log in..."; } ?&gt; </code></pre> <p><strong>Output without E_NOTICE</strong></p> <pre><code>Please log in... </code></pre> <p>Wrong! You didn't mean that!</p> <p><strong>Output with E_NOTICE</strong></p> <pre><code>Notice: Undefined variable: usernmae in /home/user/notice.php on line 3 Please log in... </code></pre> <p>In PHP, a variable that doesn't exist will return null rather than causing an error, and that could cause code to behave differently than expected, so it's best to heed <code>E_NOTICE</code> warnings.</p> <hr> <p><strong>2. TO DETECT AMBIGUOUS ARRAY INDEXES</strong></p> <p>It also warns you about array indexes that might change on you, e.g.</p> <p><strong>Example - code looks like this today</strong></p> <pre><code>&lt;?php $arr = array(); $arr['username'] = 'fred'; // then further down echo $arr[username]; ?&gt; </code></pre> <p><strong>Output without E_NOTICE</strong></p> <pre><code>fred </code></pre> <p><strong>Example - tomorrow you include a library</strong></p> <pre><code>&lt;?php // tomorrow someone adds this include_once('somelib.php'); $arr = array(); $arr['username'] = 'fred'; // then further down echo $arr[username]; ?&gt; </code></pre> <p><strong>and the library does something like this:</strong></p> <pre><code>&lt;?php define("username", "Mary"); ?&gt; </code></pre> <p><strong>New output</strong></p> <p>Empty, because now it expands to:</p> <pre><code>echo $arr["Mary"]; </code></pre> <p>and there is no key <code>Mary</code> in <code>$arr</code>.</p> <p><strong>Output with E_NOTICE</strong></p> <p>If only the programmer had <code>E_NOTICE</code> on, PHP would have printed an error message:</p> <pre><code>Notice: Use of undefined constant username - assumed 'username' in /home/user/example2.php on line 8 fred </code></pre> <hr> <p><strong>3. THE BEST REASON</strong></p> <p>If you don't fix all the <code>E_NOTICE</code> errors that you think aren't errors, you will probably grow complacent, and start ignoring the messages, and then one day when a real error happens, you won't notice it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload