ReflectionClass getDocComment返回false

时间:2013-09-02 10:59:52

标签: php reflection

我正在尝试从课程中获取文档评论,并且对于我的生活,我不知道为什么getDocComment()返回false。我期待getDocComment返回@Whatever。

<?php
/** @Whatever */
class Test {
}

$rc = new ReflectionClass("Test");
var_dump($rc->getDocComment());

输出:     布尔(假)

$ php --version
PHP 5.5.1 (cli) (built: Aug 31 2013 01:32:53) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.2-dev, Copyright (c) 1999-2013, by Zend Technologies

1 个答案:

答案 0 :(得分:3)

如果您使用的是Zend Opcache,请查看以下ini设置:

opcache.save_comments (default "1")
    If disabled, all PHPDoc comments are dropped from the code to reduce the
       size of the optimized code. Disabling "Doc Comments" may break some
       existing applications and frameworks (e.g. Doctrine, ZF2, PHPUnit)

opcache.load_comments (default "1")
    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.