Where function is declared, Get file name and line no in PHP

Sometimes when developing in PHP in large applications searching for function (without IDE) in all the files becomes boring. So I was looking for quick solution of this. By searching few minutes I found great solution.

There is a built-in PHP class ReflectionFunction

Example of ReflectionFunction Class

<?php
$r = new ReflectionFunction('selected'); // ReflectionFunction is a PHP in-built class
echo $file = $r->getFileName();		// getFileName() is inherited method.
echo $startLine = $r->getStartLine();  // getStartLine() is inherited method.
?>

Here in first line selected is function name I want to search where it’s declared.

Shyam has written 29 articles

Shyam is senior full stack developer, who loves to explore new technologies and work on them. He's passionate about coding so can code 24/7. He uses PHP as a backend programming language.

He knows Laravel, MySQL, AngularJS, ReactJS, Redis, Kubernetes, Git, CodeIgniter, PHP, MVC pattern, Lodash, jQuery, VanilaJS, Teamcity and many other technologies and tools.

Shyam writes notes and hacks on his blog (https://shyammakwana.me). In spare time he can be found @ StackOverflow or crafting any new open source application.

Passionate Programmer and Meditator #PERIOD.