Does class function exist

I'm trying to write a simple function in a class which will display debug information if the function doesn't exist. However I don't know how to specify $this->myfunction name. What I've been working on is:-

    class pageHandler {
        function showMain($arrayData) {
        function callFunction($functionName, $arrayData) {
            if (function_exists($functionName)) {
                call_user_func(array($this, $functionName),$arrayData);
            } else {
                echo "Function $functionName not yet declared<br/>" . print_r($arrayData,true);
    $newTest = new pageHandler();
    $newTest->callFunction("showMain",array('para1'=>'val1', 'para2'=>'val2'));

Open in new window

Any ideas how I should be testing function_exists for a class?

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
If you're writing the class, you can write the functions.  You do not need to test to see if class methods exist.  All of that "function_exists()" stuff leads to the kind of spaghetti code that made WordPress such a mess for so many years.  We don't do that any more!

If you're still determined to complicate your life, I can hold my nose and point to this:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tonelm54Author Commented:
I agree, however the reason I wanted to put the debug information bit in was to display what function Im missing. I need to quickly write a project, and there are a lot of functions I need to write, and as in the past few days its gone from a simple project to quite a massive one I know Im going to miss out functions, and instead of ugly errors I wanted to display a "nicer" message with the information in it.

I know usually I could get the IDE to display the error saying "function not declared", however as it will be multiple programs all feeding in (some I've got no documentation on) I wanted to simply my debugging
Ray PaseurCommented:
Yeah, I've had projects like that, too!  Best of luck with it, ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.