坑:看php官方manual文档的中文版、英文版不一样,中文版可能会有遗漏或未编写部分。
说明:
功能描述:从类中获取文档注释。文档注释以 /** 开头。如果类定义上方有多个文档注释,将采用最接近该类的注释。
ReflectionClass::getDocComment的返回值->
如果存在,则为 doc 注释,否则为false.
返回false情况1
在类的上方没有注释,或注释结构不是以 /** 开头。
返回false情况2(未尝试)
开启了 Zend Opcache后php.ini配置问题。
查看是否开启了Zend Opcache的方法:
# Zend Opcache扩展开启前
C:\Windows\system32>php -v
PHP 7.4.3 (cli) (built: Feb 18 2020 17:29:57) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
# Zend Opcache扩展开启后
C:\Windows\system32>php -v
PHP 7.4.3 (cli) (built: Feb 18 2020 17:29:57) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
php.ini内设置:
(我在win10的phpstudy里没有找到load_comments,且自行添加后ini_get读取不到)
opcache.save_comments=1;
opcache.load_comments=1;
说明
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
返回false情况3(未尝试)
服务器安装了eAccelerator的原因。
默认优化的时候删除了PHP的文档块并缓存代码编译结果,所有调用反射接口的时候返回false
编译eaccelerator的时候增加
–with-eaccelerator-doc-comment-inclusion
可参考链接:ReflectionClass getDocComment 返回false