Netbeans Auto-compeletion on php class's method

7

2

I created a php project in Netbeans 7.3. I have a class (MYSQL_DB ). When I want to access its methods inside the file that I defined the class it shows me this: Netbeans is showing methods

Note that this is out side of class definition (not using $this). But when I want to access its methods outside of this file, it shows me nothing:

Netbeans failed to show methods

Q:Is there any way to show methods when typing class name (like first image) in all files?
Thanks in advance!

undone

Posted 2013-09-04T22:29:56.353

Reputation: 824

Answers

5

I suspect that the problem is that Netbeans doesn't know the class of your variable. (That happens a lot in PHP, being weakly typed.) Right after you assign the value to the variable, put in a special type hint comment:

$database=someFunction(); /* @var $database DatabaseClass */

This hint will tell Netbeans the type of $database, allowing it to suggest methods. If you have control over the source of someFunction, you can add a hint there, too. See https://blogs.oracle.com/netbeansphp/entry/defining_a_variable_type_in for lots of examples.

David Brown

Posted 2013-09-04T22:29:56.353

Reputation: 131

If you're the author of the someFunction() that returns your $database, you should be able to add a phpDoc block ahead of the function, specifying the @return type. https://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.return.pkg.html

– David Brown – 2016-02-27T13:57:05.677

I tried that back then, didn't did what I wanted. I moved to phpstorm. – undone – 2016-02-27T15:06:42.897

This was the only answer that was working in my Netbeans 8.1 installation. Thanks! – SebiF – 2016-05-25T10:18:40.827

Thanks but didn't work! Still shows No suggestions – undone – 2013-09-04T23:10:55.663

If I put the comment before variable definition inside a function :global $database , I can see its method but there are thousands of cases like this. Is there a way to do it once and make it available in all files? – undone – 2013-09-04T23:27:03.523

3

Start by adding comments as code-hints where you variables are declared. In class properties use the long form notation for comments:

/**
 * @var \ClassName $varname
 */
 private $varname;

Within classes you can typically use the inline-comments:

/* @var \ClassName $inlinevar */
$inlinevar = new ClassName();

You may need to clear your cache, that will help when autocomplete does not work for classes in the same project. On Linux look under your home directory ~/.cache/.netbeans/ and remove the subdirectory for the project version (always back up first in case something goes wrong).

If your class lives in another project you may need to add the path to the root folder for the other project so Netbeans can scan that folder for class definitions.

Lance Cleveland

Posted 2013-09-04T22:29:56.353

Reputation: 131