使用PDT / Netbeans中的类自动完成PHP对象?

时间:2023-01-17 21:08:52

When I define an object of a class using new like this

当我使用new这样定义类的对象时

$blah = new Whatever();

I get autocomplete for $blah. But how do I do it when I have $blah as a function parameter? Without autocomplete I am incomplete.

$ blah我得到自动完成功能。但是当我将$ blah作为函数参数时,我该怎么做呢?没有自动填充我不完整。

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?

编辑:如果它在一个包含和PDT或Netbeans无法解决它怎么办?有没有办法在PHP中声明变量的类型?

2 个解决方案

#1


Method in first comment is called "type hinting", but you should use that wisely. Better solution is phpDoc.

第一个注释中的方法称为“类型提示”,但您应该明智地使用它。更好的解决方案是phpDoc。

/**
 * Some description of function behaviour.
 *
 * @param Whatever $blah
 */
public function myFunction($blah)
{
    $blah-> 
    // Now $blah is Whatever object, autocompletion will work.
}

You can also use an inline phpDoc comment which does exactly the same thing.

您还可以使用内联phpDoc注释,它完全相同。

public function myFunction($blah)
{
    /* @var $blah Whatever  */
    $blah-> 
    // Now $blah is Whatever object, autocompletion will work.
}

#2


Try to pass parameter class definition into the function:

尝试将参数类定义传递给函数:

function myFunction(Whatever $blah) {
}

#1


Method in first comment is called "type hinting", but you should use that wisely. Better solution is phpDoc.

第一个注释中的方法称为“类型提示”,但您应该明智地使用它。更好的解决方案是phpDoc。

/**
 * Some description of function behaviour.
 *
 * @param Whatever $blah
 */
public function myFunction($blah)
{
    $blah-> 
    // Now $blah is Whatever object, autocompletion will work.
}

You can also use an inline phpDoc comment which does exactly the same thing.

您还可以使用内联phpDoc注释,它完全相同。

public function myFunction($blah)
{
    /* @var $blah Whatever  */
    $blah-> 
    // Now $blah is Whatever object, autocompletion will work.
}

#2


Try to pass parameter class definition into the function:

尝试将参数类定义传递给函数:

function myFunction(Whatever $blah) {
}