在 JSDoc 中,我可以用 标记我的构造函数@constructor。现在我试图在 PHPDoc 规范中找到如何对 PHP 构造函数执行相同的操作,但他们从未提及任何类似的内容。在 PHP 中标记我的构造函数的正确方法是什么?
这:
/**
* @constructor
*/
public function __construct()
{
}
Run Code Online (Sandbox Code Playgroud)
好像无效。
我使用PhpStorm 2016.2.1IDE。我有一个类型化数组(所有成员都属于相同的已知类),我希望 IDE 知道该类型,以便它可以帮助我解决自动完成/智能感知问题。
class MyClass{
/**
* @var array
*/
public $userArray;
public addUser($uid){ $this->$userArray[$uid] = new User($uid); }
public processUser($uid){
$oUser = $this->$userArray[$uid];
//since the PHP array can contain anything, the IDE makes
//no assumption about what data type $oUser is. How to let it
//know that it's of type User?
}
}
Run Code Online (Sandbox Code Playgroud)
我努力了...
/**
* @var User
*/
public $oUser = ...;
Run Code Online (Sandbox Code Playgroud)
并且
/**
* @type User
*/
public $oUser = ...;
Run Code Online (Sandbox Code Playgroud)
到目前为止,我唯一要做的就是使用 getter 函数: …
我有许多变量的对象,我在评论中声明和解释.我正在非常彻底地评论以便使用phpDoc进行后续处理,但是我还没有实际编译文档的经验.
我觉得非常烦人的是,使用phpDoc表示法,每个变量都会占用四到六行代码,即使我想要设置的唯一属性是描述:
/**
* @desc this is the description
*/
var $variable = null;
Run Code Online (Sandbox Code Playgroud)
我想用下面的表示法:
# @desc this is the description
var $variable = null;
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来调整phpDoc接受这个,或者当我真正尝试编译文档时它会给我带来麻烦吗?我现在不需要调整(虽然它当然很受欢迎),只是来自知道phpDoc的人的声明,这是否可行,而无需重新设计其代码的大部分内容.
我正在使用PHPdocumentor记录我的CakePHP应用程序.您可能知道,在CakePHP约定之后,视图包含在.ctp文件中(例如app/views/addresses/index.ctp),它们基本上是普通的PHP文件,只是文件扩展名已更改.PHPdocumentor只识别.php文件,我在配置文件中找不到一个选项让它知道.ctp文件.这部分最接近我想要的:
;; comma-separated list of files to parse
;; legal values: paths separated by commas
;filename = /path/to/file1,/path/to/file2,fileincurrentdirectory
Run Code Online (Sandbox Code Playgroud)
但是因为它似乎没有像野生动物那样加入通配符*.php,我真的不想把我的50个视图文件列表写入这个配置文件(除非有更好的解决方案).是否有可能在全局范围内配置phpdoc以包含.ctp文件,或者我是否必须在phpdoc源中的某个地方稍微改变一下?
我想开始使用phpDocumentor并且手动安装不断抛出一个关于我没有在终端中的php.ini中设置detect_unicode = Off的错误.
当我将它添加到我的php.ini时它不需要,我在运行安装时遇到同样的问题.似乎没有人有这个问题,而对于我的生活,我无法理解.
https://github.com/phpDocumentor/phpDocumentor2/blob/develop/README.md#installation
我错过了什么?(我在php.ini编辑后重新启动了MAMP服务器)
终端错误的屏幕截图...

有没有办法将@method签名中的参数标记为phpDoc中的可选项?
像这样的东西:
/*
* @method bool alloc() alloc(int $filesize [, string &$result]) Allocates space for a file to be uploaded
*/
Run Code Online (Sandbox Code Playgroud) 我在PHPdocs阅读本:
数据类型应该是一个有效的PHP类型(int,string,bool等),"这很好,但是它们没有说明用于识别其他类型的字符串(例如int,string,bool).
我在GUESSING他们使用(强制转换)语法来确定用于注释的类型,但是像PHP中的浮点这样的东西没有一个强制转换操作符,所以我不知道该用什么.也许它是浮动的,或者它可能是fp.
有没有人有PHP的基本类型的明确列表,以及在PHPdocs中应该用什么字符串来识别它们?
是否有可能提示PhpStorm在下面的代码中返回值的item()方法有类型DOMElement(没有修改实际的PHP语句,即通过某些外部设置的PhpStorm或插件或使用某种类型的PHPDoc注释等)?
再次,请不要建议我修改代码中的语句,特别是部分$list->item(0)->getAttribute('test').
另外,我发现了一个类似的问题PhpStorm类型提示工厂?但它处理用户定义函数的类型提示,在我的例子中,该函数item()是预定义的库函数.
$doc = new DOMDocument();
$doc->loadXML('<x test="123"/>');
$list = $doc->getElementsByTagName('x');
if($list->length > 0)
var_dump($list->item(0)->getAttribute('test'));
Run Code Online (Sandbox Code Playgroud)

我目前将Eclipse Photon PDT用于旧的PHP应用程序。在此应用程序中,有很多phpdoc注释,但是其中一些被标记为错误。
有人知道如何禁用这些错误吗?(因为我的所有项目文件都标有错误图标,而我看不到哪些文件确实有错误)。
php ×10
phpdoc ×10
phpstorm ×2
annotations ×1
cakephp ×1
composer-php ×1
constructor ×1
eclipse ×1
eclipse-pdt ×1
ide ×1
intellisense ×1
mamp ×1
markup ×1
type-hinting ×1