本文介绍了ReflectionClass getDocComment 返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从课堂上获取文档评论,并且在我的一生中,我不知道为什么 getDocComment() 返回 false.我期待 getDocComment 返回 @Whatever.
I am trying to get the doc comment from a class and for the life of me, I have no idea why getDocComment() is returning false. I am expecting getDocComment to return @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
推荐答案
如果你使用的是 Zend Opcache,那么看看下面的 ini 设置:
If you're using Zend Opcache, then look at the following ini settings:
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.
这篇关于ReflectionClass getDocComment 返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!