第一:
protected function isValid($orderIds)
{
......
$orderCount = Some Calculation... ;
return ( $orderCount == count($orderIds) );
}
第二:
protected function isValid($orderIds)
{
......
$orderCount = Some Calculation... ;
return ( $orderCount == count($orderIds) ) ? 1 : 0;
}
我正在使用此功能
......
$isValid = $this->isValid($orderIds);
if($isValid) {
// do some thing here
}
请看上面的书面代码。如果我选择第一个功能而不是第二个功能,有什么问题吗?
第一种方法只会返回boolean&类型,而第二种方法只是增加开销以返回1 or 0
。如果您只需要检查该方法是否已成功完成工作,则建议您采用第一种方法。