Re: optional argument when creating a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

The ampersand does not make it optional.  It passes it by reference...
http://us2.php.net/manual/en/language.references.php

<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

To make the second variable optional, give it a value in the argument list when defining the function...

function doEmail ( $username, $link = NULL ) {

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@xxxxxxxxxxxx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux