Re: optional argument when creating a function

From: Date: Wed, 17 Aug 2005 15:17:40 +0000
Subject: Re: optional argument when creating a function
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-220759@lists.php.net to get a copy of this message
apparently the ampersand means to treat $link as a reference, not as an optional argument: http://www.softwareprojects.org/php-functions-12.htm I think the way to do it would be to set a default value in your function so that if a value is set by the calling statement that would override it: function doEmail($username, $link = false) {
    if ($link !=== false)
    {
        // "doEmail($arg1, $arg2);" gets sent here
        print "$link $username";
    }
    else
    {
        // "doEmail($arg1);" gets sent here
        print "$username";
    }
} haven't tested this, but give it a try. Jordan On Aug 17, 2005, at 10:00 AM, D A GERM wrote:
I'm throwing a warning on a function I created. I thought a & in front of the argument was supposed to make it optional. Is there something else I need to do make that argument optional? <CODE> //I simplified the code function doEmail($username, &$link) { if (isset($link)) {
     print "$link $username";
} else {
     print "$username";
} } doEmail($arg1); doEmail($arg1, $arg2); </CODE> Here is the error: Warning: Missing argument 2 for doemail() in /srv/www/htdocs/test-a/staff/email_scramble.php on line 24 thanks in advance for any help. --D. Aaron Germ Scarborough Library, Shepherd University (304) 876-5423 "Well then what am I supposed to do with all my creative ideas- take a bath and wash myself with them? 'Cause that is what soap is for" (Peter, Family Guy) --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#220759) next »