Jump to content

Handling missing function arguments

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:


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 post
Share on other sites

You can do something like

function foo($bar=null){if(isset($bar))echo $bar;elseecho 'You missed something';}

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...