Array as class property?

Termi

New Member
I have this API that requires me to have a specific array key to be send.Since that array needs to be used on ALL class methods, I was thinking on putting as a class property.\[code\]abstract class something { protected $_conexion; protected $_myArray = array();}\[/code\]Later on, on the methods of this class, I will then use:\[code\]$this->_myArray["action"] = "somestring";\[/code\](Where "action" is the key that needs to be send to this API);Is this ok? I've not seen enough OOP in front of my eyes that's why I'm asking this.As requested, here is more info about the API:\[code\]class Apiconnect { const URL = 'https://someurl.com/api.php'; const USERNAME = 'user'; const PASSWORD = 'pass'; /** * * @param <array> $postFields * @return SimpleXMLElement * @desc this connects but also sends and retrieves the information returned in XML */ public function Apiconnect($postFields) { $postFields["username"] = self::USERNAME; $postFields["password"] = md5(self::PASSWORD); $postFields["responsetype"] = 'xml'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, self::URL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); $data = http://stackoverflow.com/questions/3941859/curl_exec($ch); curl_close($ch); $data = utf8_encode($data); $xml = new SimpleXMLElement($data); if($xml->result =="success") { return $xml; } else { return $xml->message; } }}abstract class ApiSomething{ protected $_connection; protected $_postFields = array(); /** * @desc - Composition. */ public function __construct() { require_once("apiconnect.php"); $this->_connection = new Apiconnect($this->_postFields); } public function getPaymentMethods() { //this is the necessary field that needs to be send. Containing the action that the API should perform. $this->_postFields["action"] = "dosomething"; //not sure what to code here; if($apiReply->result == "success") { //works the returned XML foreach ($apiReply->paymentmethods->paymentmethod as $method) { $method['module'][] = $method->module; $method['nome'][] = $method->displayname; } return $method; } }}\[/code\]Thanks a lot,MEM
 
Back
Top