I have a class which does some API (REST) functions. I'd like to declare the variable class-wide variable and static, so I won't fetch the data over and over again. (This is what I think in theory, could be wrong) Many methods in the class will need that data.
I am using this type of class but something doesn't look right. It is working, but (this is just an example class, not the real code);
class Some_Process {
private static $tickets = array();
private function _get_tickets () {
if(!self::$tickets) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_URL, 'http://someurl');
self::$tickets = json_decode(curl_exec($curl));
if(!self::$tickets) {
return FALSE;
}
return TRUE;
}
}
function process_tickets () {
self::_get_tickets();
//here I start using the varible
do some job on .. self::$tickets;
}
}