title: Static variable resets - PHP
body: <p>For some reason my <code>static</code> variable resets and I am not sure why it resets.</p>
  
  <pre><code>public static $_pwdAdjId = 0; //static variable
  
  function ...() {
  // Piece of code that manipulates the static variable
  if(isset($_POST['adj'])) {
      self::$_pwdAdjId = $_POST['adj'];
  } else if(!isset($_POST['adj']) &amp;&amp; $_GET['ajax'] !== 'assignTable') {
      self::$_pwdAdjId = Yii::app()-&gt;user-&gt;getId();
  }
  $adj = self::$_pwdAdjId;
  ...
  }
  </code></pre>
  
  <p>When the function is first called, this will be called:</p>
  
  <p>self::$_pwdAdjId = Yii::app()->user->getId();</p>
  
  <p>and saves the value into <code>$adj</code> and it works fine.</p>
  
  <p>When the user changes the page the value that is stored into <code>$adj</code> is 0 - the initial value of the <code>static</code> variable. I am not sure why it is reseting to its initial value instead of the new value stored.</p>
  
  <p>Before First Call:</p>
  
  <p><code>self::$_pwdAdjId == 0</code></p>
  
  <p>First Call:</p>
  
  <p><code>self::$_pwdAdjId == 7</code></p>
  
  <p><code>$adj == 7</code></p>
  
  <p>Page (ajax call): Second Call:</p>
  
  <p><code>self::$_pwdAdjId == 0 // supposed to be 7</code></p>
  
  <p>Am I missing something? Does the fact that it's called via ajax the second time affect its <code>static</code>-ness?</p>
  
  <p>Thanks.</p>