I've been a php programmer for a number of years, but am only now getting into OOP. I have two classes so far, Item and List (I'm just simplifying here, they're not the real class names.) All of my data is accessed via a web service using SOAP.
I'm not sure what the best way is to implement getting a SOAP client and using it in multiple classes. For example, the WSDL defines an addItem function and a getList function. I also need to send a token to the service for each transaction.
Do I need to define a new SoapClient inside every class? like so:
class Item {
// item properties
function addItem($itemName) {
$client = new SoapClient('myfile.wsdl');
$client->addItem($itemName);
//service returns true or false
}
}
class List {
function getList($listName) {
$client = new SoapClient('myfile.wsdl');
return $client->getList($listName);
//service returns array
}
}
Or is there some way to create a new SoapClient outside of the individual classes and use the same client object in each one?
SoapClient.