我试图在我的班级的其他评论中的其他地方提及我的班级的属性,即。在该类的方法中。
例如,如果我们有这样的代码:
(请搜索property $mention -- @property Village::mention does not work:)
class Village {
/**
* @var array Data container.
*/
public $data = [];
/**
*
*/
public $mention = 'Me';
/**
* Village constructor which injects data.
*
* @param $data
*/
public function __construct($data) {
$this->data = $data;
}
/**
* A factory for our Villages.
*
* @return Village
*/
public static function hillbilly() {
return new Village;
}
/**
* Name tells the story... …Run Code Online (Sandbox Code Playgroud) 我正在将我的项目升级到 PHP 8.0+。到目前为止,在代码注释中,我使用了@param和@return标签,如“选项 1”,而不是“选项 2”:
选项1:
@param string[] ...。@return User[] ...。选项2:
@param array ...。@return array ...。不过,因为我不知道第一种形式是否被官方允许,所以我开始问自己,切换到第二种形式是否会更好......所以,我想问你:有吗?有没有可用的 PHP 代码文档官方PHPDoc 参考资料?
另外,是否建议使用第一个选项而不是第二个选项?换句话说:是否有任何反对的论据——也考虑到未来?
感谢您的时间。
PS :我找到了PHPDocumentor的参考资料,但我有一种感觉,它不是官方的 PHP 参考资料,而且还不兼容 PHP 8.0+。
我正在使用拉拉维尔。我需要知道如何在 php 8 中使用属性编写 phpdoc。
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
//Some code
return [];
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下上面的代码如何用属性来编写吗?
我最近熟悉Reflection并且一直在尝试它,特别是getDocComment(),它似乎只支持/** */注释块.
/** foobar */
class MyClass{}
$refl = new ReflectionClass('MyClass');
// produces /** foobar */
echo $refl->getDocComment();
Run Code Online (Sandbox Code Playgroud)
-与-
# foobar
class MyClass{}
$refl = new ReflectionClass('MyClass');
// produces nothing
echo $refl->getDocComment();
Run Code Online (Sandbox Code Playgroud)
如果不诉诸任何file_get_contents(__FILE__)废话,是不是可以捕获它?
根据dader51的回答,我认为我的最佳方法是这样的:
// random comment
#[annotation]
/**
* another comment with a # hash
*/
#[another annotation]
$annotations
= array_filter(token_get_all(file_get_contents(__FILE__)), function(&$token){
return (($token[0] == T_COMMENT) && ($token = strstr($token[1], '#')));
});
print_r($annotations);
Run Code Online (Sandbox Code Playgroud)
输出:
Array
(
[4] => #[annotation] …Run Code Online (Sandbox Code Playgroud) 命令行将为整个项目生成phpdoc是什么?
/Users/macuser/Sites/my-project/
index.php
config.php
includes/
class/
test.class.php
include-a.php
docs-go-in-here/
Run Code Online (Sandbox Code Playgroud)
我已经安装了PEAR phpdoc并且能够为单个php文件创建文档,我无法找到如何执行整个目录.
是否有一个特定的原因,PhpStorm以斜杠为前缀构造函数的返回类型?
class MyTest
{
/**
* Constructor
*
* @return \MyTest
**/
public function __construct(){}
}
Run Code Online (Sandbox Code Playgroud)
它在PHPDoc本身中有特殊含义吗?还是一些特定的IDE功能?
我是PHPStorm的新手,我在这个IDE中导入了一个现有的项目.现在我收到很多警告
在课堂上找不到方法'查询'
我读到了使用PHPDoc-blocks来声明当前类中未定义的变量的来源,但我无法了解我应该如何处理这种情况:
class loginModel extends Model{
public function checkLogin(){
[...]
if($this->db->query($sql)){[...]} //Warning as stated above
[...]
}
}
Run Code Online (Sandbox Code Playgroud)
$ this-> db本身是从类Model继承的:
class Model{
protected $db;
private function connect(){
$this->db = new PGSQL();
}
}
Run Code Online (Sandbox Code Playgroud)
因此可以访问名为query的公共PGSQL方法.
也许不是那么精心设计,但如何在不降低其严重性的情况下解决这些信息呢?
我有以下基本类设置:
class Document extends Eloquent {
/**
* [types description]
* @return [type] [description]
*/
public function types() {
return $this->belongsToMany('Type');
}
}
Run Code Online (Sandbox Code Playgroud)
什么值适合放入返回类型doc块?执行返回方法的var转储指向对象\ Illuminate\Database\Eloquent\Relations\BelongsToMany
在这种情况下,这是正确的吗?(我不确定为什么会这样?)
谢谢
我正在尝试正确注释我的代码,我通常不会从函数内部回显任何内容,通常我只是返回数据,然后在需要时回显返回的值。今天我写了一个函数,它只会在视图文件中经常使用,所以我想为什么不从函数内部回显,然后在需要时调用它,避免在任何地方输入回显。
我想知道是否有任何方法可以在 phpDoc 注释中表明此函数将回显字符串。诸如@sideEffect 输出或UpdateDb 或SendToQueue 之类的东西?。
/**
* Echo error class
* @param array $fields
* @param string $field
* @return void
* @sideEffect output
*/
public static function getFailedClass($fields, $field)
{
if (isset($fields[$field])) {
echo 'failedValidation';
}
}
Run Code Online (Sandbox Code Playgroud)
所以可以像这样在视图中使用:
<textarea name="data" class="<?php Lib\Validation::getFailedClass($fields, 'data'); ?>"></textarea>
Run Code Online (Sandbox Code Playgroud) 选择javadoc/phpdoc比定期评论有什么理由和情况?我知道语法差异是什么,但为什么要使用其中一个.它主要是语义还是其他原因我应该使用一个而不是另一个,它们是什么?
我真的不明白javadoc/phpdoc评论的目的.下一个代码块有什么问题?......这/**只是让某些评论在编辑器中变成不同颜色的一种方式...一些编辑不区分(香草崇高似乎不是)?
/*
* This block is wrapped in /** */ not /* */
* Some documentation goes here
* Below is copied from http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
* @param url an absolute URL giving the base location of the image
* @param name the location of the image, relative to the url argument
* @return the image at the specified URL
* @see Image
*/
Run Code Online (Sandbox Code Playgroud)
另一个问题......会有任何理由我为什么要同时使用/** */,并/* */在同一个文件?
最后的问题...为什么javadoc/phpdoc评论看起来似乎与类有关...但是我看到它们被用作对我最初理解的页面的介绍评论?
实际上又是另一个......冒着回答我自己的问题的风险我想知道javadoc/phpdoc注释真的只是区分工具自动编写的注释和开发人员编写的注释吗?