dongxiansi0158
dongxiansi0158
2013-08-17 22:51
浏览 21
已采纳

ReflectionFunction是如何工作的?

I'm trying to use the following function to loop through loaded files and find depreciated functions.

//loads all files
include dirname(__FILE__) . '/loader.php'; 

$functions = get_defined_functions();

foreach ($functions['user'] as $func) {

    $rf = new ReflectionFunction('$func');
    var_dump($rf->isDeprecated());
}

Some functions have markup like the following, yet it's still return false. In fact every single function returns false yet there are a lot with markup stating @deprecated.

 **
 *
 * @since 0.71
 * @deprecated 1.5.1
 * @deprecated Use get_post()
 *
 * @param int $postid
 * @return array
 */

ref: http://www.php.net/manual/en/class.reflectionfunction.php

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsfw2154
    dsfw2154 2013-08-17 22:59
    已采纳

    ReflectionFunction::isDeprecated does not check documentation comments; it only checks an internal flag that can be set by PHP extensions on the functions they expose.

    For example, here is the part of the source for the ereg extension where its functions are declared and marked as deprecated (the DEP part in PHP_DEP_FE stands for "deprecated").

    点赞 评论
  • dongwei7245
    dongwei7245 2013-08-17 22:59

    Looking at the source code for Reflection, it applies only to built-in functions that have the ZEND_ACC_DEPRECATED flag set, so it's not applicable to userland methods or functions

    点赞 评论

相关推荐