Reputation:
I'm new to writing OOP so if I'm missing something easy here, please forgive me. I have an object that is constructed with a path to a file. One of the methods opens the file (or halts execution if not found) and explodes the contents into an array. This array is then passed to another function that converts the array data into time.
Every subsequent function needs that converted array, but it seems like there must be a better way then having the following in the beginning of every function.
$array = $this->convert();
Is there a different aproach to this?
Upvotes: 1
Views: 45
Reputation: 64657
Just save the result to a member variable, and access it directly
class whatever {
private $array;
function convert() {
//do stuff
$this->array = $result;
return $this->array;
}
function otherFunction() {
//instead of $array you now use $this->array
}
}
Upvotes: 2