問題描述
當我像這樣使用 new 定義一個類的對象時
When I define an object of a class using new like this
$blah = new Whatever();
我得到了 $blah 的自動完成.但是當我將 $blah 作為函數參數時我該怎么做?如果沒有自動完成,我是不完整的.
I get autocomplete for $blah. But how do I do it when I have $blah as a function parameter? Without autocomplete I am incomplete.
編輯:如果它在包含中并且 PDT 或 Netbeans 無法弄清楚,我該怎么做? 有沒有辦法在其中聲明變量的類型PHP?
Edit: How do I do it if it's in an include and PDT or Netbeans can't figure it out? Is there any way to declare types for variables in PHP?
推薦答案
第一個注釋中的方法稱為類型提示",但您應該明智地使用它.更好的解決方案是 phpDoc.
Method in first comment is called "type hinting", but you should use that wisely. Better solution is phpDoc.
/**
* Some description of function behaviour.
*
* @param Whatever $blah
*/
public function myFunction($blah)
{
$blah->
// Now $blah is Whatever object, autocompletion will work.
}
您也可以使用內聯的 phpDoc 注釋,它的作用完全相同.
You can also use an inline phpDoc comment which does exactly the same thing.
public function myFunction($blah)
{
/* @var $blah Whatever */
$blah->
// Now $blah is Whatever object, autocompletion will work.
}
這篇關于自動完成帶有 PDT/Netbeans 類的 PHP 對象?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!