【发布时间】:2011-04-13 05:45:36
【问题描述】:
我想知道什么时候私有/受保护的方法应该在类上工作它的变量(比如$this->_results),以及什么时候应该像函数一样使用这些方法(比如$this->_method($results))。以下示例:
处理类属性
<?php
class TestA
{
protected $_results;
public function getResults()
{
$this->_results = getFromWebservice();
$this->_filterResults();
}
protected function _filterResults()
{
$this->_results = doMagic($this->_results);
}
}
“作为功能”工作
<?php
class TestB
{
protected $_results;
public function getResults()
{
$results = getFromWebservice();
$this->_results = $this->_filterResults($results);
}
protected function _filterResults($results)
{
return doMagic($results);
}
}
【问题讨论】: