PHP Variable declared outside of any function, not visible from functions -


been struggling make simple code work, face problem global/local reach of 1 variable.

here code try work. code contained in php file called ajax procedure javascript. none of variables appears in below chunks of code.

$location = "./treewindow/tree_structure.xml";  function openxml($url) { if (file_exists($url)) {     $xml = simplexml_load_file($url);     }  else {     echo("failed open xml @ ".$url);     exit;     } }  function cubicleavailablespace() {      openxml($location); } 

when call last function:

cubicleavailablespace(); 

i get:

failed open xml @  

why variable $location not recognized in function cubicleavailablespace()?! thought considered "visible" functions within php code...

now, sure easy, tried whole afternoon make work... looked around place, not find reply helped me (though there many such cases in website) of course, when replace variable actual value ("./treewindow/tree_structure.xml"), works: xml file @ right place :-)

can me find what's wrong , make $location variable visible in both functions ?

thanks

try

function cubicleavailablespace() {    global $location;   openxml($location); } 

you declared variable outside function not readable inside.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -