title: Unable to use variable declared in a function inside another function
body: <p>Didn't know how to ask this question.</p>
  
  <p>I was working on setting up class to handle my Database interaction and have a weird interaction of passing variables. I must be missing something.</p>
  
  <p>I have a class <code>DataBaseAPI</code> I have a function <code>QueryDB($value)</code> that will be called by other functions. But it has an issue with my declaring that <code>$value</code> inside another function. Example:</p>
  
  <p>Works</p>
  
  <pre><code>include_once('DataBaseAPI.php');
  $DB = new DataBaseAPI();
  
  $test = $DB-&gt;QueryDB('id');
  echo $test;
  </code></pre>
  
  <p>Doesn't Work</p>
  
  <pre><code>include_once('DataBaseAPI.php');
  $DB = new DataBaseAPI();
  
  $test = $DB-&gt;getId();
  echo $test;
  </code></pre>
  
  <p>Start of the class in <code>DataBaseAPI.php</code></p>
  
  <pre><code>class DataBaseAPI {
  
  
    public function getId(){
      //the same function defined the same way but needing to use $this
      $this-&gt;QueryDB('id');//seems like a waste here but is for ease of use later on
    }
  
  
    public function QueryDB($value){
      echo $value; //echo's id
      global $conn; 
      $token = '7ci4f8ykfik3ndzufksy1dp16x3na4'; //Test Token not a real token
      $doesExists = "SELECT $value FROM user_info WHERE token='$token'";
      $existsResult = mysqli_query($conn, $doesExists);
      $check = $existsResult-&gt;fetch_assoc();
      return $check[$value];
    }
  } 
  </code></pre>
  
  <p>I even checked with an echo the <code>$value</code> in the <code>QueryDB($value)</code> echo's <code>id</code> the same way as when I call the function directly. </p>
  
  <p>I just don't understand why the first method works yet the second method doesn't, yet I'm still calling it the same way. Just inside another function.  </p>