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!

Member Avatar for diafol

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

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 :)

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..

 }
commented: good link +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.