-1
我剛剛在教程中看到這個奇怪的事情,但無法弄清楚這個「評論」內的變量括號表示。你知道嗎 ?
public function addComment(Comment $comment) { ..... }
歡呼聲
我剛剛在教程中看到這個奇怪的事情,但無法弄清楚這個「評論」內的變量括號表示。你知道嗎 ?
public function addComment(Comment $comment) { ..... }
歡呼聲
這意味着參數必須是類Comment
的對象。如果傳入的參數不是Comment
對象,則PHP將引發錯誤。
此功能被稱爲「type hinting」。
爲什麼地獄會讓人失望呢?奇怪的... – Sliq 2014-11-28 14:56:08