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?
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.
}
Try to pass parameter class definition into the function:
function myFunction(Whatever $blah) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With