2012-07-06 95 views
0

在PHP 5.3>我可以鍵入提示與接口對象一個對象?型暗示了實現接口不是類

像這樣:

public function AddToFavorite(Trendmed\Interfaces\Favoriteable $entity) {} 

或IM僅限於檢查內部函數實現?我試着像上面一樣輸入提示,但它不起作用。

+1

你什麼錯誤? – xdazz 2012-07-06 09:31:31

回答

2

manual

PHP 5 introduces type hinting. Functions are now able to force parameters to be objects (by specifying the name of the class in the function prototype), interfaces, arrays (since PHP 5.1) or callable (since PHP 5.4)

所以它可以使用的接口。

+0

也許我做的事情wront但是我得到一個錯誤:AddToFavorite :: AddToFavorite()必須Trendmed \接口\ Favoriteable,代理實例的實例\ __ CG __ \ Trendmed \實體\診所給出 – 2012-07-06 09:42:28

+0

我認爲這是beacose Doctrine2使這些代理類不直接實現我的界面。開溜。 – 2012-07-06 09:45:38

+1

@BartoszRychlicki所以它意味着類型提示的作品,你通過錯誤的類型:) – xdazz 2012-07-06 09:49:28

相關問題