title: PHP undefined index in a class
body: <p>I know this has been asked before and I have looked at multiple threads on why this would happen but could not understand how mine does not work as other variables defined in the same way and gathered the same way work.</p>
  
  <pre><code>class item{
      var $name = "test";
      var $id = 3;
  
      function setId($newID){
          global $id;
          $id = $newID;
      }
  
      function getId(){
          return $GLOBALS['id'];
      }
  
      function setName($newName){
          global $name;
          $name = $newName;
      }
  
      function getName(){
          return $GLOBALS['name'];
      }
  }
  </code></pre>
  
  <p>That is a snippet of the class as it is really long but duplicate getName and setName for 5/6 more items.</p>
  
  <pre><code>$item[0]-&gt;getName();
  </code></pre>
  
  <p>Would return "test"</p>
  
  <pre><code>$item[0]-&gt;getId();
  </code></pre>
  
  <p>Returns the "Undefined index: id in <em>link to file</em> on line 59" which is the getId() function.</p>
  
  <p>Every function other then getId() works and I have no idea why</p>
  
  <p>EDIT - this question has been answered I am waiting to be able to accept an answer. $this worked for the variable to return (even though I'm still not sure why it would even though the 5 or 6 others would)</p>