Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

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

<?php
    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
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tonelm54
tonelm54

ASKER

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
Yeah, I've had projects like that, too!  Best of luck with it, ~Ray