flaab Posted September 3, 2007 Share Posted September 3, 2007 Hi =) Php has some method related functions like method_exists to check wether a function exists in a class. I need a function that returns me how many parameters does a function of a class NEED to be executed, is there any? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/67775-get-amount-of-method-parameters/ Share on other sites More sharing options...
trq Posted September 3, 2007 Share Posted September 3, 2007 func_get_args(). Quote Link to comment https://forums.phpfreaks.com/topic/67775-get-amount-of-method-parameters/#findComment-340468 Share on other sites More sharing options...
trq Posted September 3, 2007 Share Posted September 3, 2007 Sorry, just re-read your post. Use func_num_args(). Quote Link to comment https://forums.phpfreaks.com/topic/67775-get-amount-of-method-parameters/#findComment-340477 Share on other sites More sharing options...
flaab Posted September 3, 2007 Author Share Posted September 3, 2007 Thanks but i'm not pretty sure if this is what i need. What I need is checking how many parameters a function needs to be executed...before executing it =) For example: 1. We want to execute function foo of class fooClass and provide an array of parameters 2. We check if the function foo of fooClass can be executed with the amount of parameters passed 3. If the array fits the number of required parameters, we execute it. 4. If not, we do not. It has to be done from outside... Quote Link to comment https://forums.phpfreaks.com/topic/67775-get-amount-of-method-parameters/#findComment-340489 Share on other sites More sharing options...
trq Posted September 3, 2007 Share Posted September 3, 2007 Ah yeah. I thought that might be the case. You will need to use refection. Quote Link to comment https://forums.phpfreaks.com/topic/67775-get-amount-of-method-parameters/#findComment-340492 Share on other sites More sharing options...
flaab Posted September 3, 2007 Author Share Posted September 3, 2007 Thanks! I've been reading it so far and I haven't figured out the way it might help me =( Usually, when we execute a method without all required parameters, we get a warning message displayed in our browser, right? I would like to make that an error and do not displaying the result. Example: class foo { public function whatever($a, $b) { } } So if we try to execute foo::whatever(4,5) it works, but if i try to execute foo::whatever(4) it throws an execution error insted of a warning. Maybe catching the exception like this? try { foo::whatever(4); } catch (Exception $e) { // Code here } Will that work? Quote Link to comment https://forums.phpfreaks.com/topic/67775-get-amount-of-method-parameters/#findComment-340523 Share on other sites More sharing options...
flaab Posted September 3, 2007 Author Share Posted September 3, 2007 No, it does not xDD Quote Link to comment https://forums.phpfreaks.com/topic/67775-get-amount-of-method-parameters/#findComment-340554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.