2017-10-29 11:42
浏览 79


To find where a function is defined in a Laravel application I'm trying to do this:

Inside App\Http\Controllers Namespace:

$reflFunc = new ReflectionFunction('function_name');

But get an error:

PHP Error: Class 'App\Http\Controllers\ReflectionFunction' not found in /var/www/html/s/source/app/Http/Controllers/HomeController.php on line 169

I even tried to use the global namespace:

ReflectionFunction Class is not supposed to be located where laravel is trying to find it, But please suggest what is that I could be missing?

图片转代码服务由CSDN问答提供 功能建议

要查找Laravel应用程序中定义函数的位置 我正在尝试执行此操作:

内部 App \ Http \ Controllers 命名空间:

  $ reflFunc = new ReflectionFunction('function_name'); 
 <  / code>  


PHP错误:类'App \ Http \ Controllers \ ReflectionFunction'不是\ n在第169行的 /var/www/html/s/source/app/Http/Controllers/HomeController.php 中找到

我甚至尝试过 使用全局命名空间:

ReflectionFunction Class不应该位于laravel试图找到它的位置, 但是请建议我可以丢失什么? \ n

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

3条回答 默认 最新

  • dth8312 2017-10-29 11:53

    You're running this code inside class that by itself is inside namespace App\Http\Controllers. So you should explicitly define that ReflectionFunction class belongs to global namespace:

    $reflFunc = new \ReflectionFunction('function_name');
    print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();

    Notice \ReflectionFunction instead of simple ReflectionFunction

    点赞 打赏 评论
  • dongyi2993 2017-10-29 11:54

    It seems that you forgot to use ReflectionFunction; in the top of your class. Alternatively change to (notice backslash) $reflFunc = new \ReflectionFunction('function_name');

    点赞 打赏 评论
  • douduan6731 2017-10-29 11:55

    ReflectionFunction is in global namespace.


    To use a class constructor in global namespace write

    $reflFunc = new \ReflectionFunction('function_name');

    点赞 打赏 评论

相关推荐 更多相似问题