NoUser2U Posted May 27, 2011 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! Link to comment Share on other sites More sharing options...
birbal Posted May 27, 2011 Share Posted May 27, 2011 You can do something like function foo($bar=null){if(isset($bar))echo $bar;elseecho 'You missed something';} Link to comment Share on other sites More sharing options...
ShadowMage Posted May 27, 2011 Share Posted May 27, 2011 You can use the debug_backtrace() function to access information useful in generating your own error messages. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.