title: PHP calling function from another file not working
body: <p>Very basically, I'm trying to set the value of a variable in one file based on the return value of a function in another file. This is then returned via AJAX, however, the AJAX always seems to indicate an error. Code below:</p>
  
  <p>updateTurn.php</p>
  
  <pre><code>&lt;?php
  //This is called by AJAX
  require_once('functions.php'); //include necessary file
  $player = getCurrentTurn(); //call function 
  echo $player;
  ?&gt;
  </code></pre>
  
  <p>functions.php</p>
  
  <pre><code>...
  function getCurrentTurn()
  {
      //the query and connection function appropriately
      include_once("getConn.php");
      $query = $GLOBALS['conn']-&gt;prepare("SELECT turn FROM Game");
      $query-&gt;execute();
      $result=$query-&gt;fetch(PDO::FETCH_ASSOC);
      return $result['turn']; //return the result of the query
  }
  ...
  </code></pre>
  
  <p>AJAX</p>
  
  <pre><code>function checkForTurnChange(){
      $.ajax({
          type:"GET",
          url:"updateTurn.php",
          async:true,
          cache:false,
          timeout:10000,
          success:function(data){
              alert(data);
          },
          //this is where AJAX is returning
          error: function(XMLHttpRequest, textStatus, errorThrown){
              alert(textStatus +": "+ errorThrown);
          }
      });//end AJAX
  };//end function
  </code></pre>
  
  <p>The error is caused by the line <code>$player = getCurrentTurn();</code>. If I remove this and <code>echo</code> any string value then it works correctly. This is incredibly basic but I can't seem to see my error. All help appreciated.</p>
  
  <p>EDIT: The AJAX calls <code>error:</code> which results in this <code>alert</code> :</p>
  
  <p><img src="https://i.stack.imgur.com/2Kkk4.png" alt="AJAX error message"></p>