title: PHP classes and functions/ undefined variable
body: <p>Why do I get undefined property Takeover::user2 on function takeover?
  I'm not sure what I'm doing wrong. Can someone help?
  I can call user2->addsaldo() on main file but I can't call it inside another function. Why?</p>
  
  <p>Class user</p>
  
  <pre><code>class User {
  /**
   * @AttributeType int
   */
  private $iduser;
  /**
   * @AttributeType float
   */
  private $saldo=0;
  /**
   * @AssociationType Portefolio
   * @AssociationKind Composition
   */
  public $idportefolio;
  
  public function __construct($iduser){
      $this-&gt;iduser = $iduser;
  }
  
  /**
   * @access public
   */
  public function getid() {
      // Not yet implemented
  }
  
  /**
   * @access public
   */
  public function addsaldo($saldo) {
      $this-&gt;saldo = $saldo;
  }
  }
  </code></pre>
  
  <p>Class takeover</p>
  
  <pre><code>    class Takeover {
      /**
       * @AttributeType int
       */
      private $idTakeover;
      /**
       * @AssociationType root
       * @AssociationMultiplicity 1
       */
      public $Root;
  
      public $IdeasTakerover=array();
  
      public function __construct($idTakeover){
          $this-&gt;idTakeover = $idTakeover;
      }
      /**
       * @access public
       */
      public function GetIdCompraRoot() {
          // Not yet implemented
      }
  
      public function AddIdeasTakeover($idTakeover, $idideia) {
          $this-&gt;idTakeover = $idTakeover;
          $this-&gt;idideia = $idideia;
          array_push($this-&gt;IdeasTakerover,$idideia);
      }
          /**
       * @access public
       */
          public function Takeover() {
              $this-&gt;user2-&gt;addsaldo(200); //USER2 DOES EXIST
      }
  }
  </code></pre>
  
  <p>Creating users and calling them:</p>
  
  <pre><code>$takeover = new Takeover(1);
  
  for ($i=0; $i&lt;$conta; $i++ ){
      $takeover-&gt;AddIdeasTakeover(1,$idsideias[$i]);
  }
  
  $takeover-&gt;Takeover();
  
  if ($partial == "user") {
              $booleanUser = TRUE;
          $iduser=substr($buffer, 4);
          ${'user'.$iduser} = new User($iduser);
  }
  </code></pre>