Jump to content

Handling missing function arguments


NoUser2U

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...