Joshua Bakker
Joshua Bakker

Reputation: 2378

Netbeans PHPDoc local variable not working

I am trying to document my code more often and now I'm writing a class and want it to be fully documented. However, for some strange reason, local variable documentation (with PHPDoc of course) doesn't work..

I got this:

/**
 * A function for question
 * @param string $theVar The var to put in local var $aVar.
 */
public function theFunction($theVar) {
    /** @var string This is new local var, should have documentation but hasn't... */
    $aVar = $theVar;
}

So when I type 'the' and press space, and go to my function in Netbeans, it shows the function documentation.

But, when I type 'aVa' inside the function and press space and go to my variable, it says 'PHPDoc not found'.

I know in this case it wouldn't be a problem, but in a big function with lots of code it could actually be useful. However, for some reason it doesn't work and I have no clue why.

Upvotes: 3

Views: 2658

Answers (3)

Pascual Muñoz
Pascual Muñoz

Reputation: 329

This is a different Tweak for Netbeans. You have to delete one *.

/* @var int This documentation is for $bVar. */
$bVar = 10;

In the 8.2 version of Netbeans, you have a template: vdoc to do quick:

/* @var $$${VARIABLE variableFromNextAssignmentName default="variable"} ${VAR_TYPE variableFromNextAssignmentType default="ClassName"} */

Upvotes: 1

cyphi1
cyphi1

Reputation: 31

This should work within a local variable. Just learning about PHPDoc, but I'm using it in PHPStorm and it works as long as you don't explicitly include the local variable name in the documentation.

paste this in your IDE:

<?php
    /** @var int This documentation is for $aVar. */
    $aVar = 5;

    /** @var int This documentation is for $bVar. */
    $bVar = 10;

    if ($bVar !== $aVar) {
        echo "False";
    }

Upvotes: 1

Machavity
Machavity

Reputation: 31654

I don't think you can document internal variables like that. You can document class variable declarations and function parameters but the documentation doesn't say anything about a local function variable

You may use the @var tag to document the “Type” of properties, sometimes called class variables. Examples

class Foo
{
  /** @var string|null Should contain a description */
  protected $description = null;
}

Even compound statements may be documented:

class Foo
{
  /**
   * @var string $name        Should contain a description
   * @var string $description Should contain a description
   */
  protected $name, $description;
}

Upvotes: 1

Related Questions