Reputation: 1669
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?
Upvotes: 4
Views: 1369
Reputation: 1721
ReflectionFunction is in global namespace.
see: http://php.net/manual/en/class.reflectionfunction.php
To use a class constructor in global namespace write
$reflFunc = new \ReflectionFunction('function_name');
Upvotes: 1
Reputation: 369
It seems that you forgot to use ReflectionFunction;
in the top of your class. Alternatively change to (notice backslash) $reflFunc = new \ReflectionFunction('function_name');
Upvotes: 1
Reputation: 4570
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
Upvotes: 8