2012-10-25 46 views
0

Possible Duplicate:
Can’t use method return value in write contextPDO和OOP空()方法

爲什麼,當我嘗試此=>

if(empty($pQuery1->fetch(PDO::FETCH_ASSOC))){} 

我得到這個錯誤:

致命錯誤:無法使用方法的返回值寫上下文

但是,當我嘗試這個它完美的作品...

$resultats = $pQuery1->fetch(PDO::FETCH_ASSOC); 
if (empty($resultats)){ 
// ... 
} 

有人可以解釋我爲什麼嗎?我不明白。

+1

http://stackoverflow.com/search?q=%5Bphp%5D+Fatal+error%3A+Can%27t+use+method+return+value+in+write+context –

+0

來自文檔:*空( )只檢查變量,否則會導致分析錯誤* – Esailija

+0

謝謝我真的應該習慣在提出任何問題之前閱讀文檔。 – Ydhem

回答

1

empty()僅適用於不在返回值上的變量。

+0

好吧,謝謝! – Ydhem

+0

這是因爲empty()比方法更像是一個php關鍵字。它會抑制警告,例如在空($ array ['non_existent_key'])上。 – jonas