7

I work for a company where employees both use PHPStorm and Netbeans 8. This has always been working fine for us until we recently started added more type hinting to our code.

In PHPStorm the correct way to use type hinting in your source like this

/** @var MyAwesomeClass $theObject */
$theObject = $orm->getMyAwesomeObject();

Which makes sense because the correct way to document a function is

/**
 * @param MyAwesomeClass $awesomeObjectArgument
 * @param boolean $booleanArgumentsAreSilly
 */

But netbeans works like this

/** @var $theObject \Full\Freeking\Namespace\With\Leading\Backslash\MyAwesomeClass */

Which is an issue because the order of arguments (to the @var notation) is reversed, and Netbeans uses leading slashes which is not supported by PHPStorm.

Does anybody know a way to configure either one of these IDE's to work with the same standard, because at the moment only half of our code has working autocompletion. To me the implementation in Netbeans seems unnecessarily and conflicting with the PHPDocs standard (based on the @param notation).

UPDATE: I was wrong, PHPStorm is actually compatible with the Netbeans notation, but not the other way around. Meaning my problem is not completely fixed. I still need to find a way to configure both IDE's to generate docs that work in both.

1
  • I don't understand what you're talking about, in Netbeans (7.*, 8.*), when you auto-document a variable (type /** then hit ENTER, one line before a variable), it automatically writes * @var type $variable on the next line. And it understand this notation for code hints, of course... Commented Apr 26, 2016 at 8:50

2 Answers 2

8

Which is an issue because the order of arguments (to the @var notation) is reversed, and Netbeans uses leading slashes which is not supported by PHPStorm

This is NOT true.

1. PhpStorm supports both orders (@var [type] [variable] as well as @var [variable] [type])

2. PhpStorm supports both PHPDoc comments (/** @var ...) as well as ordinary block comments (/* @var ...)

3. PhpStorm supports FQN -- this works just fine: /** @var $theObject \Full\Namespace\MyAwesomeClass */

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

You are correct, I incorrectly assumed PHPStorm wouldn't be able to deal with the reversed notation. PHPStorm supporting both fixes the issue for PHPStorm users but not for netbeans users. Is there any way to change the template for PHPStorm so it automatically autocompletes the same way netbeans does it?
"PHPStorm supporting both fixes the issue for PHPStorm users but not for netbeans users" -- Then use netbeans-compatible notation everywhere (if you need such compatibility). Or write some custom script that would find such non-compatible entries and swap order to make them compatible.
"Is there any way to change the template for PHPStorm so it automatically autocompletes the same way netbeans does it?" -- All available for customisation templates are located in Settings | File & Code Templates. If there is none for your case-- then it's not available. You can create custom Live Template and use it for making such PHPDoc comments. In any case: PhpStorm follows PHPDoc standards and it's not PhpStorm's problem that some another IDE works differently (especially since PhpStorm supports that "other" way).
I'd note that there actually is no "PHPDoc Standard" with regard to using @var to denote datatyping on "local variables"... this practice in IDEs developed "in the wild", hence the differences in implementation. The phpDocumentor team is working through PHP-FIG to include this use case in its proposed PSR-5 standard for PHP documentation syntax (github.com/php-fig/fig-standards/pull/169), though it specifies a new @type tag to replace @var.
@LazyOne @ashnazg, the RFC proposal seems almost stable now (may 2017), endorsing that the futur of variable php documentation will be similar to properties and constants: /** @var Type $var */. github.com/phpDocumentor/fig-standards/tree/master/proposed
|
2

Despite ashazg's assertion that there is no PHPDoc standard for type hinting, the official documentation at http://phpdoc.org/docs/latest/references/phpdoc/tags/var.html does say that typehint should precede variable name, and there is no mention in the documentation that this order is just a suggestion and that anyone can just use their own ordering.

Also, this practice is consistent with most other languages that are strongly typed, such as Java (public int speed) or C (int speed). So the fact that Netbeans does not support the correct typehint order as in PHPDoc documentation is causing a lot of pain.

2 Comments

My assertion regarded "local variables". Those are class variables at the documentation link you provide, which have always been available to be documented as per the standard. The OP question was solely about "local variables", which the IDEs tried to solve outside of the standard... hence the differing implementations.
Point taken. However, differing standards (or lack thereof) between local and class variables PHPDoc and the standard syntax already established in above mentioned languages does/did cause a lot of pain. I hope this will be taken care of with PSR-5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.