Reply to Re: [PHP] optional argument when creating a function

Your name:

Reply:


Posted by John Nichel on 08/17/05 18:13

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@kegworks.com

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация