title: How to resolve non-existant index in array?
body: <p>I have my own class for templates. In this class, I replace string likes <code>{NEXT_PAGE}</code> to </p>
  
  <pre><code>&lt;?php echo $tpl-&gt;vars["NEXT_PAGE"]; ?&gt;
  </code></pre>
  
  <p>But sometimes happen, that this index doesn't exists.</p>
  
  <p>I found topic <a href="https://stackoverflow.com/questions/4495130/php-is-array-on-arrkey-with-non-existing-key">PHP: is_array on $arr['key'] with non existing 'key'</a> and I know how to check if some index exists. </p>
  
  <p>My question is, what is better to improve performance.</p>
  
  <ol>
  <li>Always check if index exist and if yes, print it</li>
  <li>Just print it without checking if index exists.</li>
  </ol>
  
  <p>First solution is great, no warning, no errors, no notices, but I go through array twice, first time to check it, second time to print it. Need more CPU time.</p>
  
  <p>Second solution just try to find it, if it exists print it, otherwise print empty string, it's OK for me, and warnings I can disable by <code>error_reporting</code></p>
  
  <hr>
  
  <p>So what is better? I think that second solution with disabling warnings. PHP always have to check if index exists, but when I check it too, it is checked twice. Am I right?</p>
  
  <p>Just to be clear, accessing to index which doesn't exists is max 3% of all accessing to this array.</p>
  
  <hr>
  
  <p><strong>Example</strong>
  I have a form, where I put back login name, if pass is incorrect.
  When I replace <code>{LOGIN_NAME}</code> by <code>&lt;?php echo $tpl-&gt;vars["LOGIN_NAME"]; ?&gt;</code> I save this new file like a PHP script, so later I just run this, no replacing again!</p>
  
  <p>So my compiled script is something like this</p>
  
  <pre><code>&lt;form ...&gt;
  &lt;input type="login" ... value="&lt;?php echo $tpl-&gt;vars["LOGIN_NAME"] ?&gt;" /&gt;
  (pass etc...)
  &lt;/form&gt;
  </code></pre>
  
  <p>So when someone visit this page for the first time LOGIN_NAME isn't set, PHP can't print anything but it's OK, field is still empty. If form is send, script add to LOGIN_NAME sent login name and then field isn't empty.</p>