Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining variable type in Netbeans PHP

Tags:

php

netbeans

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?

like image 826
Andy Avatar asked Dec 17 '12 15:12

Andy


2 Answers

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, e.g. 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 ;-)

like image 54
Álvaro González Avatar answered Sep 28 '22 00:09

Álvaro González


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

like image 34
shadyyx Avatar answered Sep 27 '22 23:09

shadyyx