0
我有一類這樣的:我可以從另一個函數返回返回值嗎?
class Example {
private function _test($value)
{
if ($value == 'xyz') return FALSE;
}
public function check()
{
$this->_test('xyz');
// more code follows here...
}
}
基本上就是我想要做的是「冒泡」的返回值從方法_test()的方法檢查()的實際的返回值FALSE,所以在調用
$this->_test('xyz');
將返回FALSE
return $this->_test('xyz');
將無法工作,因爲我不想返回,如果值不匹配「XYZ」。
這可能嗎?
我明白我可以做到這一點。但是我想避免check()方法中的if子句,而是從_test方法繼承返回值。 – santacruz
如果你只*想在特定條件爲真時返回,你別無選擇,只能使用某種'如果'構造。 –
然後只需執行'$ result = $ this - > _ test('xyz')'?你能解釋一下你期望更清楚的發生嗎? check()函數的最終目標是什麼? – Prisoner