简体   繁体   English

Netbeans和PHPStorm中的变量类型提示

[英]Variable type hinting in Netbeans and PHPStorm

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. 我在一家员工都使用PHPStorm和Netbeans 8的公司工作。在我们最近开始为我们的代码添加更多类型提示之前,我们一直都很好。

In PHPStorm the correct way to use type hinting in your source like this 在PHPStorm中正确使用类型提示的方法就像这样

/** @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 但是netbeans就是这样的

/** @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. 这是一个问题,因为参数的顺序(对@var表示法)是相反的,而Netbeans使用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. 有没有人知道如何配置这些IDE中的任何一个使用相同的标准,因为目前只有一半的代码具有工作自动完成功能。 To me the implementation in Netbeans seems unnecessarily and conflicting with the PHPDocs standard (based on the @param notation). 对我来说,Netbeans中的实现似乎是不必要的,并且与PHPDocs标准(基于@param表示法)相冲突。

UPDATE: I was wrong, PHPStorm is actually compatible with the Netbeans notation, but not the other way around. 更新:我错了,PHPStorm实际上与Netbeans表示法兼容,但不是相反。 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. 我仍然需要找到一种方法来配置两个IDE来生成在两者中都有效的文档。

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 这是一个问题,因为参数的顺序(对@var表示法)是相反的,而Netbeans使用PHPStorm不支持​​的前导斜杠

This is NOT true. 这不是真的。

1. PhpStorm supports both orders ( @var [type] [variable] as well as @var [variable] [type] ) 1. PhpStorm支持两个命令( @var [type] [variable]以及@var [variable] [type]

2. PhpStorm supports both PHPDoc comments ( /** @var ... ) as well as ordinary block comments ( /* @var ... ) 2. PhpStorm支持PHPDoc注释( /** @var ... )以及普通块注释( /* @var ...

3. PhpStorm supports FQN -- this works just fine: /** @var $theObject \\Full\\Namespace\\MyAwesomeClass */ 3. PhpStorm支持FQN - 这很好用: /** @var $theObject \\Full\\Namespace\\MyAwesomeClass */

在此输入图像描述

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. 尽管ashazg断言没有类型提示的PHPDoc标准,但http://phpdoc.org/docs/latest/references/phpdoc/tags/var.html上的官方文档确实说明typehint应该在变量名之前,并且在文档中没有提到这个命令只是一个建议,任何人都可以使用他们自己的订单。

Also, this practice is consistent with most other languages that are strongly typed, such as Java (public int speed) or C (int speed). 此外,这种做法与大多数其他强类型语言一致,例如Java(public int speed)或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. 因此,Netbeans不支持PHPDoc文档中正确的typehint顺序这一事实导致了很多痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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