简体   繁体   中英

Defining variable type in Netbeans PHP

I have found a way to say netbeans type of variable in such way:

/* @var $variablename Type */

However in this case there are no hints (Database is my class):

 //model.php
 abstract class Model {
      /* @var $db Database */
      protected $db;
      (...)
 }

 //Mymodel.php
 class MyModel extends Model {
      (...)
       $this->db-> //no hints
      (...)
 }

Is it Netbeans limit or rather my mistake?

NetBeans can make use of two similar yet different comment annotations:

  1. Good old phpdoc block comments, that start with /** and are placed right before the item definition :

     /** * @var Database $db Database connection instance */ protected $db; 
  2. Variable type inline comments, that start with /* and are placed somewhere before the item use :

     $foo = $this->db; /* @var $foo Database*/ $foo->... 

The second type comes in handy when docblock comments are either not available or not helpful, eg you are using a third-party library that isn't documented or your variable type cannot be tracked automatically.

You were basically using syntax for #2 in the context for #1 ;-)

First of all, define the variable type first, like this:

/* @var Database $db This is my Database object */

And secondly I would suggest to use phpdoc commenting, like:

class Model {

/**
 * @var Database $db This is my Database object
 */
protected $db;

Should have no issues then...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM