Re: The default values of variables in a function
| From: | php3 at developersdesk dot com | Date: | Mon, 25 Sep 2000 01:58:03 +0000 |
| Subject: | Re: The default values of variables in a function | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-17477@lists.php.net to get a copy of this message | ||
Addressed to: "Matt" <matt@smokescreen.org>
php-general@lists.php.net
** Reply to note from "Matt" <matt@smokescreen.org> Thu, 21 Sep 2000 22:03:40 -0400
>
> I'm trying to set a default value for a variable in a php function. See
> function below. With the following, it gives me an error because I'm using
> a variable:
>
> function RunQuery($sql,$datasource=$app_mySQL_DSN)
>
> if I change it to this, it works:
>
> function RunQuery($sql,$datasource="theDSN")
>
> Any ideas as to my this is happening or if there is a work around?
In PHP default variables must be constants.
Workaround:
function RunQuery( $sql, $datasource="TaKe ThE DeFaUlT" ) {
if( 'TaKe ThE DeFaUlT' == $datasource ) $datasource = $ap_mySQL_DSN;
..
}
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com