title: Creating a variable in PHP that can only be accessed by one function
body: <p>I have a variable that is only used by 1 function. Right now, I'm declaring the variable as a global variable and using <code>global</code> inside the function to access the variable. However, I'm afraid I might override the variable elsewhere by accident. Is there a way to make a variable accessible by only 1 function without using a class?</p>
  
  <p>Here's an example of what I want:</p>
  
  <pre><code>$i=0;
  function increment(){
    global $i;
    $i++;
    echo $i;
  }
  
  for($j=0;$j&lt;10;$j++)
    increment();
  // outputs 12345689
  </code></pre>