NoUser2U 0 Posted May 27, 2011 Report Share Posted May 27, 2011 Dear all,I have a problem i need to solve which needs to handle functions and missing but specified arguments. Let's say i have a function foo, with argument $bar: <?php function Foo($bar){ echo $bar;}?> When i call this function with an argument inside, for example foo('test'), then output is 'test'....no probs. BUT, I need to be able to call this function without giving argument, for example, calling this function like: <?phpfoo()?> Of course, when called like that, i'll show a custom error page, like one saying 'Argument missing' or so (for example, with die('argument missing!'))....How would i do that? I hope it can be taken care of with __call, but if possible, how would i do that since __call accepts 2 parameters? (see http://www.php.net/manual/en/language.oop5...oading.methods)Much thanks in advance! Quote Link to post Share on other sites
birbal 168 Posted May 27, 2011 Report Share Posted May 27, 2011 You can do something like function foo($bar=null){if(isset($bar))echo $bar;elseecho 'You missed something';} Quote Link to post Share on other sites
ShadowMage 94 Posted May 27, 2011 Report Share Posted May 27, 2011 You can use the debug_backtrace() function to access information useful in generating your own error messages. Quote Link to post Share on other sites
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.