Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 245
Joshua Bakker Avatar asked Aug 05 '26 14:08

Joshua Bakker


2 Answers

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;
}
like image 139
Machavity Avatar answered Aug 07 '26 04:08

Machavity


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";
    }
like image 45
cyphi1 Avatar answered Aug 07 '26 04:08

cyphi1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!