Been struggling to make some simple code work, but face a problem with the global/local reach of one variable.
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.
$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);
}
When I call the last function:
cubicleAvailableSpace();
I get:
Failed to open XML at
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...
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 :-)
Can you help me find what's wrong and make this $location variable visible in both functions ?
Thanks