title: Undefined variable: position
body: <p>Sorry guys, I am reading and searching over the web and I cannot find a solution for this :(.
  If you can please help me :) Thanks.</p>
  
  <p>If I hard code <strong>position</strong> then it works well. I already tried this on several different ways...</p>
  
  <p>P.S.
     I have to create some kind of image gallery ajax page for exercise :) I assume this <strong>position</strong> variable should be in singleton/static class i guess. I was not able to test this class yet, but I think this will work only for first and last image always :) (in java code this would be very easy to do :) ). </p>
  
  <p>Error:
   <strong>Notice: Undefined variable: position in D:\Wamp\www\test\gethint.php on line 11</strong></p>
  
  <pre><code>&lt;?php
  
  class Index {
      private $position=1;
  
      public function next(){
          return $position++;;
      }
  
      public function prev(){
          return $position--;
      }
  
       public function reset(){
          $position=1;
          return $position;
      }
  }
  
  $action=$_REQUEST["action"];
      $index = 0;
  
  if($action!=1){
      $index=Index::prev();
  } else {
      $index=Index::next();
  }
  
  if($index &lt; 1){
      $index=7;
  }
  if($index &gt; 7){
      $index=1;
  }
  
      $response="&lt;img border=\"0\" src=\"".$index.".jpg\" alt=\"".$index."\" width=\"500\" height=\"334\"&gt;";
  
   echo $response;
   ?&gt;
  </code></pre>