Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ReflectionClass getDocComment返回false_Php_Reflection - Fatal编程技术网

Php ReflectionClass getDocComment返回false

Php ReflectionClass getDocComment返回false,php,reflection,Php,Reflection,我试图从类中获取doc注释,我不知道为什么getDocComment()返回false。我希望getDocComment返回@Whatever <?php /** @Whatever */ class Test { } $rc = new ReflectionClass("Test"); var_dump($rc->getDocComment()); 如果您使用的是Zend Opcache,请查看以下设置: opcache.save_comments (default "1")

我试图从类中获取doc注释,我不知道为什么getDocComment()返回false。我希望getDocComment返回@Whatever

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

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

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

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.

你在使用字节码缓存吗,比如APC?是的,我在使用Zend OPcache。谢谢Mark。设置opcache.save_comments=1修复了它。非常感谢。我花了很多时间试图弄明白为什么phpunit忽略了dataprovider,阅读了很多没有意义的解决方案。它失败了,因为opcache没有保存评论!如何在travis.yml中设置?
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.