How to use the output of one method as the input on another?
I'm trying to figure out how to use the output of algorithm as the input of findLarge. algorithm produces an array that I would like to work on in findLarge
开发者_C百科class CSVParser
{
public $output = NULL;
public $digits = NULL;
public $largest = NULL;
public function __construct($file)
{
if (!file_exists($file)) {
throw new Exception("$file does not exist");
}
$this->contents = file_get_contents($file);
$this->output = array();
$this->digits = array();
$this->largest = array();
}
public function algorithm() {....}
public function findLarge($a)
{
// just push it back so I know it's working
var_export($a); // is NULL
$this->largest = $a; // return NULL
}
}
$parser->algorithm();
$parser->findlarge($input); print_r($parser->largest);
It looks like you're just looking for:
$parser->findlarge($parser->algorithm());
You might want to consider, however, a couple of things.
- PHP already has
str_getcsv
- Whether it might be a better idea for
algorithm
to callfindLarge
on its own. It looks like this class has two conflicting purposes. One is storing the data, the other is processing it. You might want to think about either havingalgorithm
stateless and having a separate DO, or having algorithm modify the instance's state.
精彩评论