By declaring $xml inside a function, I believe it's only available inside that function. If your desire is to create a GLOBAL, don't use a function. Instead just do:
PHP Code:
$xml=simplexml_load_file("sw-popup.xml");
Then later for your other code, just do:
PHP Code:
<?php
echo $xml->recentPRs;
?>
I think there are ways to have the function make a GLOBAL though, check global in the man:
http://php.net/manual/en/language.variables.scope.php
It shows how to take a GLOBAL and act on it in a function. It might be able to be used to create a GLOBAL in a function. But, as I said, if you want a GLOBAL, the easiest thing is to just not use a function to create it. I think this would do it though:
PHP Code:
<?php
function load_sw_popup(){
$GLOBALS['xml']=simplexml_load_file("sw-popup.xml");
}
?>
Then later:
PHP Code:
<?php
load_sw_popup();
echo $xml->recentPRs;
?>
Bookmarks