473,231 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

[HELP] trying to pass by reference to an optional function parameter

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?

Thanks very much for any help you can give.

JT
jo********@yahoo.com__nospam
Jul 17 '05 #1
5 2518
I have used this type of passing the variable by reference in the
optional parameter. But it was in PHP 5. When I tried to use the same
function in some other project, in the PHP 4.3.9, I got the same error
message, but in PHP 5, it was working perfectly. So, I guess, it is not
for PHP 4. Not sure.

Also I am looking forward to get the reason and the solution for it.

Jul 17 '05 #2
You can't do it in PHP 4. It doesn't make a whole lot of sense to have
a reference to nothing.

Just return the value.

Jul 17 '05 #3
> Just return the value.
I am already using the return for a different value -- the one that always
gets returned -- so I need a different method to get the optional value out.

The PHP manual has a message saying you can pass a reference in the call to
the function
e.g.,
function foo($bar = null) {
$bar = 242;
}
foo(&$x); // $x == 242

but that still gives me a warning.

How about an array? I know some languages automatically pass all arrays as
references. Does PHP do this? I attempted this, but it didn't work, but
maybe I'm doing it wrong.

Unfortunately, my web host is using PHP 4.3.2, not PHP 5.
It doesn't make a whole lot of sense to have a reference to nothing. It's not the nothing that it's objecting to, it is not legal to have any
default value for a parameter passed by reference.

Thanks,
JT

<ch***********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... You can't do it in PHP 4. It doesn't make a whole lot of sense to have
a reference to nothing.

Just return the value.

Jul 17 '05 #4
John T said the following on 10/06/2005 21:52:
It doesn't make a whole lot of sense to have a reference to nothing.


It's not the nothing that it's objecting to, it is not legal to have any
default value for a parameter passed by reference.


Yes, by definition passing a reference means that you're passing a
pointer to an existing variable. If that variable doesn't exist, there
is nothing to set to NULL if you do something like:

function funQueryDatabase($strQuery, &$intInsertId = NULL)

So by definition this doesn't make sense.

--
Oli
Jul 17 '05 #5
Return the two values in an array, then use list() to separate them
out.

function a() {
...
return array($var1, $var2);
}

list($ret1, $ret2) = a()

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: SB | last post by:
Ok, very simple problem. I'm trying to update a value by calling a function using pass by reference, but it does not update the value. In short, the value I'm trying to update is balance, which is...
8
by: Don | last post by:
I have a third party C++ DLL that I am trying to use from C#. The specific function I am trying to use is declared in C++ as follows: ladybugConvertToMultipleBGRU32( LadybugContext ...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
0
by: Edwinah63 | last post by:
Hi guys, i am not new to vb6, but a mere tyro in vb.net what i want to do is the following open transaction build an ADODB command object using parameters execute it build another command...
3
by: Michael | last post by:
Hi all, I'm trying to figure out how to use setupapi.dll in C#, specifically the SetupDiCallClassInstaller function. I'm trying to develop a test suite which tests drivers and part of this...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
3
by: GS | last post by:
I have this: Public Function CleanHtml(ByVal strHtml As String, Optional ByVal doc As HtmlDocument = WebBrowser1.Document) As String flagged by vb as Error 5 Reference to a non-shared member...
2
by: jblau | last post by:
I am trying to pass a reference through a couple of layers of functions, and I am getting a C2664 Error. Here is my setup: I have a class which contains a pointer to an object . I have a...
1
by: KayC | last post by:
Hi I am using Access2002 I have a form with 5 text boxes which are parameters to a function 3 parameters are optional in the function How do I pass the empty textbox values to a optional...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.