2012-03-16 248 views
-1

我剛剛在教程中看到這個奇怪的事情,但無法弄清楚這個「評論」內的變量括號表示。你知道嗎 ?

public function addComment(Comment $comment) { ..... } 

歡呼聲

+0

爲什麼地獄會讓人失望呢?奇怪的... – Sliq 2014-11-28 14:56:08

回答

8

這意味着參數必須是類Comment的對象。如果傳入的參數不是Comment對象,則PHP將引發錯誤。

此功能被稱爲「type hinting」。