我们如何在PHP中使用define()定义(使用phpDocumentor)常量?
我在文档中找不到任何内容,但在sample2.php中找到了以下示例(我没看到它的用法):
/**#@+
* Constants
*/
/**
* first constant
*/
define('testing', 6);
/**
* second constant
*/
define('anotherconstant', strlen('hello'));
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我用phpDocumentor在PHP中记录常量的最佳方法是什么?
好吧,我确实有我的类方法上面的这个phpdoc
/**
* this a function that translates the text
* @param string|boolean $lang if string the string given in the parameter will be the language code that will represent the language desired, if true, this will translate based on the website's current language, if false will not translate.
*/
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,我是如何定义$lang只能接受字符串和布尔值的数据类型.
在我看到的其他文档中,mixed但它在我的带有PDT的Eclipse IDE中没有正确反映.
我的问题是我如何能够显示某种可能接受两种或更多种数据类型的标准方法@param.
注意:我给出的phpdoc是我现在正在使用的应用程序的现有文档.好吧,我被指派记录好一切.
我已经为php doc块设置了代码检查,所以现在如果它们丢失或不完整我会收到警告.

当我打开一个类时,我可以使用它Code > Generate > PhpDocBlocks来生成它们,或者只是/*在方法前面开始注释,它将被添加.
此外,如果exsiting doc块不完整或错误,我可以使用Update DocBlock以便将方法的DocBlock与实际方法的签名相匹配.
是否有一种方法可以应用这些文件块,如果需要,可以在整个代码库中更新doc块,而无需在每个类中手动初始化它?
我正在寻找一个批处理过程.
希望有人在这里知道一件事或两件事.
简短的问题
我在命令行上使用phpdoc遇到错误,在PHP 7.0.2上通过pear安装.错误是:
#> phpdoc
PHP Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException:
You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1.
in /usr/local/php5-7.0.2-20160108-102134/lib/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:193
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
细节
Opcache已启用并opcache.load_comments=1位于我的opcache.ini文件中,分别使用命令:php -i | grep "Opcode"和验证php -i | grep "opcache".在该.ini文件中,我可以通过检查启用并通过该文件禁用opcache来验证是否加载了更改.
话虽如此,如果我opcache.load_comments=1在我的.ini文件中,为什么我仍然会收到此错误?
谢谢!
假设我有一个名为Color的PHP类,它的构造函数接受各种参数.
// hex color
$myColor = new Color('#FF008C');
// rgb channels
$myColor = new Color(253,15,82);
// array of rgb channels
$myColor = new Color(array(253,15,82));
// X11 color name
$myColor = new Color('lightGreen');
Run Code Online (Sandbox Code Playgroud)
我应该如何使用phpDoc为构造函数和其他类似的方法创建API文档?
如何使用phpDoc重载方法?
class Color {
/**
* Constructor
* what should be here?
*/
public function __construct() {
/* CODE */
}
}
Run Code Online (Sandbox Code Playgroud) 例:
/**
* This function will determine whether or not one string starts with another string.
* @param string $haystack <p>The string that needs to be checked.</p>
* @param string $needle <p>The string that is being checked for.</p>
* @param boolean $case[optional] <p>Set to false to ignore case(capital or normal characters)</p>
* @return boolean <p>If the $haystack string does start with the $needle string, the return will be true. False if not.</p>
*/
function endsWith($haystack,$needle,$case=true) {
if($case){return (strcmp(substr($haystack, strlen($haystack) - …Run Code Online (Sandbox Code Playgroud) 如何在phpDoc中将方法标记为"返回当前类的实例"?
在以下示例中,我的IDE(Netbeans)将看到setSomething始终返回一个foo对象.
但是,如果我扩展对象,那就不是真的 - 它会返回$this,在第二个例子中,它是一个bar对象而不是一个foo对象.
class foo {
protected $_value = null;
/**
* Set something
*
* @param string $value the value
* @return foo
*/
public function setSomething($value) {
$this->_value = $value;
return $this;
}
}
$foo = new foo();
$out = $foo->setSomething();
Run Code Online (Sandbox Code Playgroud)
很好 - setSomething返回foo- 但在下面的例子中,它返回一个bar..:
class bar extends foo {
public function someOtherMethod(){}
}
$bar = new bar();
$out = $bar->setSomething();
$out->someOtherMethod(); // …Run Code Online (Sandbox Code Playgroud) 我无法理解为什么PhpStorm会PHPDoc comment does not match function or method signature对此方法给出以下警告:
/**
* Create a new instance of the class
* @param string $classname Class to instantiate
* @return object the instance
* @throw FactoryException If the class is not instantiable
*/
private function newInstance($classname) {
$reflectionClass = new \ReflectionClass($classname);
if (! $reflectionClass->isInstantiable()) {
throw new FactoryException("The class $classname is not instantiable.");
}
return new $classname;
}
Run Code Online (Sandbox Code Playgroud)
警告不是很具体,我已经尝试过几种方法,例如将返回类型更改为"对象","混合"或甚至"整数"(尝试),但它没有改变.这里有什么问题 ?
我在我们的服务器上安装了phpDoc,设置等等.它正确地生成文档.我们正在使用"响应式"模板,但无论使用何种模板,都会发生此错误.
在"错误"下,扫描的每个文件似乎都有以下错误:
Type Line Description
error 0 No summary was found for this file
Run Code Online (Sandbox Code Playgroud)
我已经详尽地搜索了这个,但无法找到解决方案.我甚至已经完成了跟踪消息背后的服务器错误代码PPC:ERR-50000并尝试追踪导致错误的条件的努力,但有点丢失.
我的问题:
这个错误是什么意思?为什么它在第0行,我怎么能摆脱它?!即使我已正确完成docblock,我可以隐藏此错误吗?我没有错误的ocd疯了!
非常感谢
编辑 一些额外的信息:我的每个文件都有来自文件第1行的以下docblock:
<?php
/**
* Short Description
*
* Long Description
*
* @package Some Package
* @subpackage Some Subpackage
* @category Some Category
* @author F Bloggs <gbloggs@email.com>
*/
?>
Run Code Online (Sandbox Code Playgroud)