0

I've considered myself somewhat of a procedural PHP expert, there is nothing I can't solve...Except this.

You know when you try to declare a function that already exists and in the error you get a reference to where the function is located, the file and line number?

Well, I am building a website where, as the Web Master, I have my own little special section. In that section, I have a page that lists all the user delcared functions.

For each function, I would like to get the file and line it is declared, so that when I need to work on the site - a function in particular - I can find it by looking at this page.

Since PHP tells me the file and line a function is declared on error (when you redeclare a function for instance) that surely there must be a way to do this manually.

I've had use for this many times in the past when working on large projects and had trouble locating functions...redeclaring them seams to work, but there has to be a better way.

Thanks!

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by veedeoo
0

This is one of the reasons you may wish to go oop to avoid this redeclaring.

0

I have thought about OOP, I am starting in on an idea for a login class to grasp the full flavor of OOP. BUT I'd still like an answer for my question for the existing projects I've got going on :)

3

You could try using ReflectionFunction class as shown here -> http://php.net/manual/en/class.reflectionfunction.php and just call it something similar to this. Will only work on php 5..

$findMyFunction = new ReflectionFunction('Name_Of_Function_You_Need_to_look_At');

## print will work better here than echo ..

print $findMyFunction->getFileName() . ':' . $findMyFunction->getStartLine();

Checking if the function exist before calling it will also help greatly..

 if(!function_exists('some_function'){

 ## do some_function..

 }
Votes + Comments
good link
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.