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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With