PHP ReflectionClass getDocComment返回false

坑:看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

其他相关参考:
PHP-ReflectionClass getDocComment返回false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值