title: PHP Variable declared outside of any function, not visible from functions
body: <p>Been struggling to make some simple code work, but face a problem with the global/local reach of one variable.</p>
  
  <p>Here is the code I try to get to work. This code is contained in a PHP file called by an AJAX GET procedure from Javascript. None of the GET variables appears in the below chunks of code.</p>
  
  <pre><code>$location = "./Treewindow/tree_structure.xml";
  
  function openXML($url) {
  if (file_exists($url)) {
      $xml = simplexml_load_file($url);
      } 
  else {
      echo("Failed to open XML at ".$url);
      exit;
      }
  }
  
  function cubicleAvailableSpace() { 
      openXML($location);
  }
  </code></pre>
  
  <p>When I call the last function:</p>
  
  <pre><code>cubicleAvailableSpace();
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Failed to open XML at 
  </code></pre>
  
  <p>Why is the variable $location not recognized in the function cubicleAvailableSpace()?! I thought it would be considered as "visible" from all functions within this PHP code...</p>
  
  <p>Now, I am sure this is easy, but I tried the whole afternoon to make this work... Looked all around the place, but could not find any reply which helped me (though there are many such cases in this website)
  Of course, when I replace the variable by its actual value ("./Treewindow/tree_structure.xml"), everything works: the XML file is at the right place :-)</p>
  
  <p>Can you help me find what's wrong and make this $location variable visible in both functions ?</p>
  
  <p>Thanks</p>