|
Posted by Kimmo Laine on 06/07/05 14:07
"John T" <johntutton@sbcglobal.net_nospam> wrote in message
news:Licpe.588$%j7.389@newssvr11.news.prodigy.com...
>I am trying to make a function that takes an optional parameter that gets
> passed by reference.
>
> Here is the first line of my function definition:
>
> function funQueryDatabase($strQuery, &$intInsertId = NULL) {
>
> I am getting this error:
>
> Parse error: parse error, expecting `')'' in c:\program
> files\easyphp1-8\www\my_query_database_function.php on line 7
>
> Line 7 is the first line of my function definition (above).
>
> If I take out the & or if I take out the = NULL, then the error goes away,
> but of course it doesn't do what I want.
>
> Is it not possible to have an optional pass-by-reference parameter, or is
> there another value that I should use for the default value?
This has been disuceesd in The Manual's user comments. Here's a post on that
topic by "bishop" quoted from
http://fi.php.net/manual/en/functions.arguments.php (wouldn't hurt to take a
look at the entire page)
"Functions explicitly prototyped with formal parameters passed by reference
can't have default values. However, functions prototyped to assign default
values to formal parameters may be passed references.
For example, this is a parse error:
function foo(&$bar = null) {
// formal parameters as references can't have default values
$bar = 242;
}
While this is perfectly legal (and probably what you want, mostly):
function foo($bar = null) {
$bar = 242;
}
foo(); // valid call, no warnings about missing args
foo(&$x); // valid call, post $x == 242
"
And this has been asked in here also earlier...
--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com
[Back to original message]
|