468,533 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,533 developers. It's quick & easy.

skipping arguments in function call

I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and
then specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);

.... but Php does not seem to want to let me do this. I get a parse
error until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed
in Php?

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #1
9 2065
My suggestion would be to reorganise the order in which the function takes
it arguments. Simply change it so that the 7th argument is the 5th, and the
5th and 6th argumentss become the 6th and 7th.

That's what I'd do at least. HTH
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:ho********************@comcast.com...
I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and then
specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);

... but Php does not seem to want to let me do this. I get a parse error
until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed in
Php?

--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

Jul 17 '05 #2
Aidan wrote:
My suggestion would be to reorganise the order in which the function takes
it arguments. Simply change it so that the 7th argument is the 5th, and the
5th and 6th argumentss become the 6th and 7th.

That's what I'd do at least. HTH

Well, yes, that would work. I can even supply the 5th and 6th arguments
in this case, but I was wondering if that really is something that Php
does not allow (the ,,, - method of skipping arguments) or if I need to
look closer for another parse error.

"Chuck Anderson" <we************@seemy.sig> wrote in message
news:ho********************@comcast.com...

I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and then
specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);

... but Php does not seem to want to let me do this. I get a parse error
until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed in
Php?

--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************


--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #3

"Chuck Anderson" <we************@seemy.sig> wrote in message
news:Cs********************@comcast.com...
Aidan wrote:
My suggestion would be to reorganise the order in which the function takes
it arguments. Simply change it so that the 7th argument is the 5th, and
the 5th and 6th argumentss become the 6th and 7th.

That's what I'd do at least. HTH
Well, yes, that would work. I can even supply the 5th and 6th arguments in
this case, but I was wondering if that really is something that Php does
not allow (the ,,, - method of skipping arguments) or if I need to look
closer for another parse error.


Well, the method you're using is essentially (to the best of my knowledge)
passing null values to the arguments you're trying to skip. Here's a page
from php.net I think you should read:

http://au3.php.net/manual/en/functio...iable-arg-list

HTH


"Chuck Anderson" <we************@seemy.sig> wrote in message
news:ho********************@comcast.com...
I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and then
specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);

... but Php does not seem to want to let me do this. I get a parse error
until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed
in Php?

--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************


--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

Jul 17 '05 #4

"Aidan" <no***********@gmail.com> wrote in message
news:ne********************@titan.linknet.com.au.. .

"Chuck Anderson" <we************@seemy.sig> wrote in message
news:Cs********************@comcast.com...
Aidan wrote:
My suggestion would be to reorganise the order in which the function
takes it arguments. Simply change it so that the 7th argument is the
5th, and the 5th and 6th argumentss become the 6th and 7th.

That's what I'd do at least. HTH
Well, yes, that would work. I can even supply the 5th and 6th arguments
in this case, but I was wondering if that really is something that Php
does not allow (the ,,, - method of skipping arguments) or if I need to
look closer for another parse error.


Well, the method you're using is essentially (to the best of my knowledge)
passing null values to the arguments you're trying to skip. Here's a page
from php.net I think you should read:

http://au3.php.net/manual/en/functio...iable-arg-list

HTH


Ahh, try this link: http://php.net/manual/en/functions.arguments.php


"Chuck Anderson" <we************@seemy.sig> wrote in message
news:ho********************@comcast.com...

I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and
then specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);

... but Php does not seem to want to let me do this. I get a parse
error until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed
in Php?

--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************


Jul 17 '05 #5

"Chuck Anderson" <we************@seemy.sig> wrote in message
news:ho********************@comcast.com...
I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and then
specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);
if you wrote myfunction, then declare it like this

function myfunction(arg1, arg2, arg3, arg4, arg5="", arg6="", arg7)...
Where "" should be set to the default values.

... but Php does not seem to want to let me do this. I get a parse error
until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed in
Php?

--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

Jul 17 '05 #6
Aidan wrote:
"Aidan" <no***********@gmail.com> wrote in message
news:ne********************@titan.linknet.com.au. ..

"Chuck Anderson" <we************@seemy.sig> wrote in message
news:Cs********************@comcast.com...

Aidan wrote:

My suggestion would be to reorganise the order in which the function
takes it arguments. Simply change it so that the 7th argument is the
5th, and the 5th and 6th argumentss become the 6th and 7th.

That's what I'd do at least. HTH

Well, yes, that would work. I can even supply the 5th and 6th arguments
in this case, but I was wondering if that really is something that Php
does not allow (the ,,, - method of skipping arguments) or if I need to
look closer for another parse error.

Well, the method you're using is essentially (to the best of my knowledge)
passing null values to the arguments you're trying to skip. Here's a page
from php.net I think you should read:

http://au3.php.net/manual/en/functio...iable-arg-list

HTH


Ahh, try this link: http://php.net/manual/en/functions.arguments.php

I have read those pages about functions and function arguments from the
manual, but I can't find any indication about whether arguments can be
skipped in the call to the function, as I cited above. It discusses
setting a default value of NULL in the function definition, but I don't
see it addressing skipping arguments in the function call. It says to
put the arguments with default values on the right side, and then it
sort of implies that you may not be able to leave out arguments.

I'm not sure where I learned the ",,," syntax for skipping arguments
(C?), but I'm beginning to think that Php simply does not support it.

I could use Variable-length argument lists, but I didn't want to go there.

"Chuck Anderson" <we************@seemy.sig> wrote in message
news:ho********************@comcast.com...

>I have a function with 7 inputs. The last three have default values.
>
>I want to call that function specifying the first four, skip two and
>then specify the last.
>
>I thought I could write this as :
>
>$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);
>
>... but Php does not seem to want to let me do this. I get a parse
>error until I supply values for the 5th and 6th arguments.
>
>My question is simply this; is skipping arguments like that not allowed
>in Php?
>
>
>


--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #7
Jamie Meyers wrote:
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:ho********************@comcast.com...

I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and then
specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);
if you wrote myfunction, then declare it like this

I did write it.
function myfunction(arg1, arg2, arg3, arg4, arg5="", arg6="", arg7)...
Where "" should be set to the default values.

That's actually something the manual says not to do. It says all default
arguments should be on the right and then has an example showing why it
won't work the other way.

My arg 7 has a default value, though, so you're structure is how it
already exists.

... but Php does not seem to want to let me do this. I get a parse error
until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed in
Php?


--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #8
On Wed, 08 Jun 2005 19:06:52 -0600, Chuck Anderson <we************@seemy.sig>
wrote:
I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and
then specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);

... but Php does not seem to want to let me do this. I get a parse
error until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed
in Php?


It's not allowed.

One alternative if you want to skip any argument and you can't rearrange the
skippable ones all towards the end is to pass an associative array instead,
which make it looks like named parameters from other languages, e.g.:

myfunction(array(
arg2 => 'wibble',
arg6 => 'wobble'
));

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #9
Andy Hassall wrote:
On Wed, 08 Jun 2005 19:06:52 -0600, Chuck Anderson <we************@seemy.sig>
wrote:
I have a function with 7 inputs. The last three have default values.

I want to call that function specifying the first four, skip two and
then specify the last.

I thought I could write this as :

$retval = myfunction(arg1, arg2, arg3, arg4,,,arg7);

... but Php does not seem to want to let me do this. I get a parse
error until I supply values for the 5th and 6th arguments.

My question is simply this; is skipping arguments like that not allowed
in Php?


It's not allowed.

One alternative if you want to skip any argument and you can't rearrange the
skippable ones all towards the end is to pass an associative array instead,
which make it looks like named parameters from other languages, e.g.:

myfunction(array(
arg2 => 'wibble',
arg6 => 'wobble'
));

Thanks. Yes, ... I can make "other arrangements." I just wanted to be
sure that was "illegal" before I wrote off ever trying it again.

--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Geoff Bennett | last post: by
12 posts views Thread by John Devereux | last post: by
21 posts views Thread by dragoncoder | last post: by
9 posts views Thread by Csaba Gabor | last post: by
13 posts views Thread by pozz | last post: by
7 posts views Thread by Gustaf | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.