ReflectionMethod->getDocComment() 似乎不适用于 PHP 5.5



我正试图用reflectionMethods为我的一个类创建一个接口,但我遇到了一个问题,方法getDocComments()在我的暂存环境中失败。

这是我使用的测试代码:

<?php
class foo
{
/**
* Method bar description
*
* @param string $param1
* @param int    $param2
* @return array
*/
public static function bar($param1, $param2 = 0)
{
return array();
}
}
$r        = new ReflectionMethod('foo', 'bar');
$docBlock = $r->getDocComment();
echo $docBlock;

在我的暂存环境中,$docBlock是空的(如果我var_dump()it,则设置为false)。我在暂存环境中的PHP版本是PHP Version 5.5.30-1~dotdeb+7.1。在我的本地环境中,有了PHP Version 5.6.27-0+deb8u1,它似乎可以工作。

这个问题可能是我的环境特有的,但我无法在我找到的任何在线php测试仪上复制它(我用PHPEster和在线php函数测试了它,他们允许对几个版本的php进行测试,但没有一个具有我在环境中的精确版本。

好的,Zend OPcache似乎在这个环境中被激活了,参数如下:

; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
opcache.save_comments=0
; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments"
; may be always stored (save_comments=1), but not loaded by applications
; that don't need them anyway.
;opcache.load_comments=1

opcache.save_comments设置为0时,所有注释(包括docBlocks)都将被删除,因此不可读。

最新更新