skipping arguments in function call

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chuck Anderson

    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

    Integrity is obvious.
    The lack of it is common.
    *************** **************
  • Aidan

    #2
    Re: skipping arguments in function call

    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" <websiteaddress @seemy.sig> wrote in message
    news:houdnQf0jJ q5CzrfRVn-hw@comcast.com. ..[color=blue]
    >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.
    > *************** **************[/color]


    Comment

    • Chuck Anderson

      #3
      Re: skipping arguments in function call

      Aidan wrote:
      [color=blue]
      >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
      >
      >[/color]
      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.
      [color=blue]
      >
      >"Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
      >news:houdnQf0j Jq5CzrfRVn-hw@comcast.com. ..
      >
      >[color=green]
      >>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.
      >>************* *************** *
      >>
      >>[/color]
      >
      >
      >
      >[/color]


      --
      *************** **************
      Chuck Anderson • Boulder, CO

      Integrity is obvious.
      The lack of it is common.
      *************** **************

      Comment

      • Aidan

        #4
        Re: skipping arguments in function call


        "Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
        news:Cs2dneTX7c MrNDrfRVn-1w@comcast.com. ..[color=blue]
        > Aidan wrote:
        >[color=green]
        >>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
        >>[/color]
        > 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.[/color]

        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:



        HTH

        [color=blue]
        >[color=green]
        >>
        >>"Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
        >>news:houdnQf0 jJq5CzrfRVn-hw@comcast.com. ..
        >>[color=darkred]
        >>>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.
        >>>************ *************** **[/color]
        >>
        >>
        >>[/color]
        >
        >
        > --
        > *************** **************
        > Chuck Anderson • Boulder, CO
        > http://www.CycleTourist.com
        > Integrity is obvious.
        > The lack of it is common.
        > *************** **************[/color]


        Comment

        • Aidan

          #5
          Re: skipping arguments in function call


          "Aidan" <nospam.aweraw@ gmail.com> wrote in message
          news:newscache$ nnushi$rt6$1@ti tan.linknet.com .au...[color=blue]
          >
          > "Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
          > news:Cs2dneTX7c MrNDrfRVn-1w@comcast.com. ..[color=green]
          >> Aidan wrote:
          >>[color=darkred]
          >>>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
          >>>[/color]
          >> 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.[/color]
          >
          > 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[/color]

          Ahh, try this link: http://php.net/manual/en/functions.arguments.php
          [color=blue]
          >
          >[color=green]
          >>[color=darkred]
          >>>
          >>>"Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
          >>>news:houdnQf 0jJq5CzrfRVn-hw@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.
          >>>>*********** *************** ***
          >>>
          >>>
          >>>[/color]
          >>
          >>
          >> --
          >> *************** **************
          >> Chuck Anderson . Boulder, CO
          >> http://www.CycleTourist.com
          >> Integrity is obvious.
          >> The lack of it is common.
          >> *************** **************[/color]
          >
          >[/color]


          Comment

          • Jamie Meyers

            #6
            Re: skipping arguments in function call


            "Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
            news:houdnQf0jJ q5CzrfRVn-hw@comcast.com. ..[color=blue]
            >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);[/color]

            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.
            [color=blue]
            >
            > ... 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.
            > *************** **************[/color]


            Comment

            • Chuck Anderson

              #7
              Re: skipping arguments in function call

              Aidan wrote:
              [color=blue]
              >"Aidan" <nospam.aweraw@ gmail.com> wrote in message
              >news:newscache $nnushi$rt6$1@t itan.linknet.co m.au...
              >
              >[color=green]
              >>"Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
              >>news:Cs2dneTX 7cMrNDrfRVn-1w@comcast.com. ..
              >>
              >>[color=darkred]
              >>>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.
              >>>
              >>>[/color]
              >>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
              >>
              >>[/color]
              >
              >Ahh, try this link: http://php.net/manual/en/functions.arguments.php
              >
              >
              >[/color]
              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.
              [color=blue][color=green]
              >>
              >>[color=darkred]
              >>>>"Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
              >>>>news:houdnQ f0jJq5CzrfRVn-hw@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?
              >>>>>
              >>>>>
              >>>>>[/color]
              >>[/color][/color]

              --
              *************** **************
              Chuck Anderson • Boulder, CO

              Integrity is obvious.
              The lack of it is common.
              *************** **************

              Comment

              • Chuck Anderson

                #8
                Re: skipping arguments in function call

                Jamie Meyers wrote:
                [color=blue]
                >"Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
                >news:houdnQf0j Jq5CzrfRVn-hw@comcast.com. ..
                >
                >[color=green]
                >>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);
                >>
                >>[/color]
                >
                >if you wrote myfunction, then declare it like this
                >
                >[/color]
                I did write it.
                [color=blue]
                >function myfunction(arg1 , arg2, arg3, arg4, arg5="", arg6="", arg7)...
                >Where "" should be set to the default values.
                >
                >[/color]
                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.
                [color=blue]
                >
                >[color=green]
                >>... 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?
                >>
                >>
                >>[/color][/color]

                --
                *************** **************
                Chuck Anderson • Boulder, CO

                Integrity is obvious.
                The lack of it is common.
                *************** **************

                Comment

                • Andy Hassall

                  #9
                  Re: skipping arguments in function call

                  On Wed, 08 Jun 2005 19:06:52 -0600, Chuck Anderson <websiteaddress @seemy.sig>
                  wrote:
                  [color=blue]
                  >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?[/color]

                  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(arra y(
                  arg2 => 'wibble',
                  arg6 => 'wobble'
                  ));

                  --
                  Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                  <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                  Comment

                  • Chuck Anderson

                    #10
                    Re: skipping arguments in function call

                    Andy Hassall wrote:
                    [color=blue]
                    >On Wed, 08 Jun 2005 19:06:52 -0600, Chuck Anderson <websiteaddress @seemy.sig>
                    >wrote:
                    >
                    >
                    >[color=green]
                    >>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?
                    >>
                    >>[/color]
                    >
                    > 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(arr ay(
                    > arg2 => 'wibble',
                    > arg6 => 'wobble'
                    >));
                    >
                    >
                    >[/color]
                    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

                    Integrity is obvious.
                    The lack of it is common.
                    *************** **************

                    Comment

                    Working...