php - ReflectionClass getDocComment 返回 false

标签 php reflection

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

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

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

输出: bool (假)

$ 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设置:

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.

关于php - ReflectionClass getDocComment 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18571602/

相关文章:

php - 我可以创建一个可以在没有括号的情况下调用的 PHP 函数吗?

javascript - 注释javascript函数参数?

php - 当我将 URL 作为参数传递时 Apache 失败

php - 如何在 Codeigniter 中将事件 session ID 解析为外键

java - 使用 Java 反射,如何将参数化类型的参数获取到方法?

java - 尽管 MethodHandle 正常,为什么我在 invokeExact 上收到 WrongMethodTypeException

c# - 如何使用反射在派生类的属性之前获取基类的属性

go - 如何访问未导出的结构字段

php - 使用php编辑mysql记录数据库

php - 有人可以从我的服务器外部访问我的数据库吗?