Site icon Shyam Makwana

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.

Exit mobile version