我有这个带有可选参数的构造函数.这个问题的主要问题是可用性.使用我的框架的开发人员会立即头疼,因为他不知道他是否可以提供论证,什么样的论点,或者他是否根本不能.结论:这很糟糕.但是如果某人有像Netbeans这样的合理IDE,那么PHPDoc可能会有所帮助;)
所以:
class ChildClass extends ParentClass {
public function __construct() {
$tplFile = func_get_arg(0);
if (!isset($tpl)) {
$tpl = 'index';
}
parent::__construct($tpl);
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在这里使用PHPDoc来表明可以提供一个可选的[$ tpl]参数?
假设我有一个这样的评论块:
/**
* comment
* comment
* comment
*/
Run Code Online (Sandbox Code Playgroud)
当我在这个块中打开一个新行时,我希望vim启动它
/**
* comment
* _
* comment
* comment
*/
Run Code Online (Sandbox Code Playgroud)
但是标准(ubuntu)vim脚本中的autoindent开始一个空行,如下所示:
/**
* comment
_
* comment
* comment
*/
Run Code Online (Sandbox Code Playgroud)
是否有一个修改过的脚本或命令会使vim这样做(我记得几年前我有这个功能,但现在不能google)?
TIA.
我已经下载了Netbeans 7.0 beta,因为我想给PhpDoc功能一个bash,但无法让它工作.我似乎在netbeans中的PhpDoc的配置选项上摔倒了.它要求脚本位置,

但无论我输入什么,我都会得到错误;
** ERROR *****************************************************************
* Sorry, can't find the php.exe file.
* You must edit this file to point to your php.exe (CLI version!)
* [Currently set to C:\usr\local\php\cli\php.exe]
*
* NOTE: In PHP 4.2.x the PHP-CLI used to be named php-cli.exe.
* PHP 4.3.x renamed it php.exe but stores it in a subdir
* called /cli/php.exe
* E.g. for PHP 4.2 C:\phpdev\php-4.2-Win32\php-cli.exe
* for PHP 4.3 C:\phpdev\php-4.3-Win32\cli\php.exe
**************************************************************************
Press any key to continue . . . …Run Code Online (Sandbox Code Playgroud) 是否有正确的方法来记录使用的常量define()?@var真的没有意义.我唯一能想到的是省略标记,只需在PHPdoc注释中编写描述即可.
也许我并不完全理解,但我正在尝试将{@link}内联PHPDoc标记链接到类中的另一个方法(有问题的docblock用于"速记别名"方法)
我实际上没有为文档生成任何内容,但它{@link}在NetBeans方法描述符中显示为纯文本.我是否在语法上做错了(如果我编译文档会这样做吗?)或者只是NetBeans无法支持内联{@link}?
例如:
class MyClass
{
/**
* Shorthand alias for {@link MyClass::method()}
*
* @param mixed $foo
* @param mixed $bar
* @return mixed
*/
public function __invoke($foo, $bar)
{
return $this->method($foo, $bar);
}
/**
* Does stuff with $foo and $bar
*
* @param mixed $foo
* @param mixed $bar
* @return mixed
*/
public function method($foo, $bar)
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud) 为了便于维护和IDE类自动完成和成员提示,我在我的项目中使用了PHPDoc.鉴于此示例类:
class my_class {
public $id;
public $name;
public $number;
public function __construct() {
//Do something
}
public function Rename($name) {
$this->name = $name;
}
}
Run Code Online (Sandbox Code Playgroud)
我更愿意用类文档本身记录所有属性($id,$name和$number),它们在类声明之上,然后在每个方法上面放置方法文档(如果需要).这是我最终希望我的班级看起来像:
/**
* Represents an example class for Stackoverflow
*
* @property int $id The id of the object
* @property string $name The name of the object
* @property int $number The number of the object
*/
class my_class {
public $id;
public $name;
public $number;
public …Run Code Online (Sandbox Code Playgroud) 尝试安装PHPDocumentor与PEAR安装后没有成功,我尝试手动,如官方网站上详细说明:http://www.phpdoc.org/docs/latest/for-users/installation.html
我下载了文件并在/ usr/bin /上创建别名但是当我尝试通过终端y执行phpdoc.php时它显示错误.
这是我尝试的:
> cd /usr/bin/
> ./phpdoc.php
Run Code Online (Sandbox Code Playgroud)
这是错误:
PHP Warning: include_once(/Applications/MAMP/htdocs/phpdocumentor/src/phpDocumentor/../../vendor/autoload.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/phpdocumentor/src/phpDocumentor/Bootstrap.php on line 72
PHP Warning: include_once(): Failed opening '/Applications/MAMP/htdocs/phpdocumentor/src/phpDocumentor/../../vendor/autoload.php' for inclusion (include_path='/Applications/MAMP/bin/php/php5.3.6/lib/php/:/Applications/MAMP/bin/php/php5.3.6/lib/bin/') in /Applications/MAMP/htdocs/phpdocumentor/src/phpDocumentor/Bootstrap.php on line 72
PHP Fatal error: Class 'phpDocumentor_Task_Runner' not found in /Applications/MAMP/htdocs/phpdocumentor/bin/phpdoc.php on line 37
Run Code Online (Sandbox Code Playgroud)
我正在使用Mac Os X,正如您所看到的,我使用MAMP来运行Apache.这里发生了什么?为什么它试图打开一个不存在的文件?(因为它在PHPDocumentor文件夹中确实不存在)
谢谢.
documentation phpdoc documentation-generation code-documentation
我一直在尝试使用自定义模板来处理PHPDocumentor(2)而没有太多运气.他们网站上的文档不完整,我有点难过.
我所做的是下载完整模板的副本并在我的命令中引用它,如下所示:
php phpdoc.php
--template=/path/to/customtemplate/
-d /path/to/php/source/files
-t /path/to/generated/content/
Run Code Online (Sandbox Code Playgroud)
该命令运行正常:它正确生成文档但似乎忽略了该--template选项 - 至少,我/customtemplate忽略了对文件夹中的模板文件所做的任何更改.
任何人都有任何想法?
(提前致谢!)
假设我有一堂课
class Class1
{
public function method1(){
return "hello world";
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个在课堂上使用它的课程
class Class2
{
/** @var $firstClass Class1 */
private $firstClass;
public function __construct($firstClass)
{
$this->firstClass = $firstClass;
}
public function method2()
{
return $this->firstClass-> "I want code completion to work here"
}
}
Run Code Online (Sandbox Code Playgroud)
如何使用PHPDoc使代码完成工作.我搜索了phpdoc的范围,声明,各种东西.我无法弄清楚phpdoc的注释行的术语或位置来选择它.
我正在使用phpstorm.救命!
PHP 5可以执行一些(有限的)类型提示,但是,在我看来,在现实世界的项目中,类型通常在文档注释中描述。例如,代替此:
/**
* Test method
*/
function test(SomeType $param1) {
...
}
Run Code Online (Sandbox Code Playgroud)
更常见的是
/**
* Test method
*
* @param SomeType param1
*/
function test($param1) {
...
}
Run Code Online (Sandbox Code Playgroud)
两种方法的优缺点是什么?如果我认为PhpDoc方法更常见,那是为什么呢?人们为什么不更多地使用内置语言功能?
编辑:第三个选项是将两种方法结合使用:
/**
* Test method
*
* @param SomeType param1
*/
function test(SomeType $param1) {
...
}
Run Code Online (Sandbox Code Playgroud)
但是,我个人并不经常使用它(看过Symfony或PHPUnit之类的库),老实说这似乎是在做一些工作而没有太多额外的好处。也许这就是为什么它不经常出现的原因。
phpdoc ×10
php ×6
netbeans ×3
auto-indent ×1
netbeans-7 ×1
oop ×1
phpstorm ×1
type-hinting ×1
vim ×1
windows ×1