Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReflectionFunction Not found in laravel

Tags:

php

laravel

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?

like image 819
Ramesh Pareek Avatar asked Dec 23 '22 13:12

Ramesh Pareek


1 Answers

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

like image 95
Flying Avatar answered Jan 12 '23 19:01

Flying