問(wèn)題描述
當(dāng)我像這樣使用 new 定義一個(gè)類(lèi)的對(duì)象時(shí)
When I define an object of a class using new like this
$blah = new Whatever();
我得到了 $blah 的自動(dòng)完成.但是當(dāng)我將 $blah 作為函數(shù)參數(shù)時(shí)我該怎么做?如果沒(méi)有自動(dòng)完成,我是不完整的.
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 無(wú)法弄清楚,我該怎么做? 有沒(méi)有辦法在其中聲明變量的類(lèi)型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?
推薦答案
第一個(gè)注釋中的方法稱為類(lèi)型提示",但您應(yīng)該明智地使用它.更好的解決方案是 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.
}
您也可以使用內(nèi)聯(lián)的 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.
}
這篇關(guān)于自動(dòng)完成帶有 PDT/Netbeans 類(lèi)的 PHP 對(duì)象?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!