douding7189 2017-03-06 14:35
浏览 196
已采纳

PhpStorm - 无法找到申报单

I try to lookup the declaration of File but PhpStorm says Cannot find declaration to go to.

enter image description here

I also tried it with netbeans, it can't find the declartion too. I also tried to lookup the alias use File;

enter image description here

I get No usage found in project files.

How does my code even know what it has to do if It can't find any declarations? This makes no sense to me.

How can I find out where File is declared?

  • 写回答

3条回答 默认 最新

  • duankua3620 2017-03-06 14:44
    关注

    How does my code even know what it has to do if It can't find any declarations?

    By using an autoloader. This is basically a function which is called whenever an unknown class is referenced, and attempts to define it, usually by including a file according to some naming convention. You will need to find how your particular framework manages this.

    Note that it's possible it's including a file from outside the directory you have set up as the "project" in your IDE. Once you've figured out where it is, you may be able to configure your IDE to know about these extra files.

    How can I find out where File is declared?

    Find a place where the class is used, and using a debugger or just "dump value and die", you can use ReflectionClass::getFilename() to find out about it:

    $r = new \ReflectionClass(File::class);
    $r->getFilename();
    

    Note that the File::class syntax (available since PHP 5.5) gives you the fully qualified name of the class, ignoring any aliasing or namespace imports.

    It's also possible for an extension (a library written in C, not PHP) to define a class. In that case, ReflectionClass::getFilename() will return false, and you'll need to use ReflectionClass::getExtensionName(), then track down the documentation for that extension.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败