Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete for PHP Objects with classes in PDT/Netbeans?

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

$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.

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?

like image 568
Dan Rosenstark Avatar asked Dec 23 '08 22:12

Dan Rosenstark


2 Answers

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.
}

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.
}
like image 53
Alan Gabriel Bem Avatar answered Sep 28 '22 07:09

Alan Gabriel Bem


Try to pass parameter class definition into the function:

function myFunction(Whatever $blah) {
}
like image 39
maxnk Avatar answered Sep 28 '22 06:09

maxnk