dongwuli5105 2015-02-27 15:17
浏览 75
已采纳

我可以告诉ReflectionClass构造函数区分大小写吗?

I have encountered a very interesting problem. I have two classes: APISession and ApiSession. I have an API class as well, which has a method, like this:

public static function request($category, $name, $params) {
    $params["Response"] = new APIResponse();
    $class = new ReflectionClass("API".$category);
    return $class->getMethod($name)->invoke(null, $params);
}

I am calling the method:

$result = API::request("Session", "Check", array());

Naturally, I expect this to execute the Check method of the APISession class, however, I receive the following problem:

Fatal error: Uncaught exception 'PHPErrorException' with message 'Exception 'ReflectionException' with message 'Method Check does not exist'

I have checked the source of the problem and it is caused by the fact that the request is reaching ApiSession instead of APISession, despite the fact that the string passed to it is "APISession". My question is: is it possible to tell the ReflectionClass constructor to be case-sensitive?

  • 写回答

1条回答 默认 最新

  • douxiong3234 2015-02-27 15:52
    关注

    Class names are case insensitive in PHP, this can be demontrated by executing this on command line:

    php -r 'class APISession { } class ApiSession { }'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?