I'm trying to call some "global/static" variables($agent, $version) inside a class but I don't know how to insert them in the class itself . Basically I declare the class "$myclass = new myClass($agent, $version) but I don't know how to call these variables inside the class (e.g. use them in the getProducts function ). I know the questions sounds stupid but I just don't get it .
index.php :
$myclass = new myClass($agent, $version);
$agent = "firefox";
$version = "234";
$catalog = $myClass->$getProducts("http://amazon.com", "red");
myclass.class.php :
class myClass {
function getXML ($agent, $version) {
//do something
return $
}
function getProducts ($url, $color) {
$product = $this->getXML($agent, $version);
$catalog = str_replace("asus", "", $product);
return $catalog
}
}
class myClass. Then initialize$agentand$version. Only after that you can instantiate itnew myClass($agent, $version). But you did the reverse!