arguments from function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iulian.ilea

    arguments from function

    Hey,

    I try to explain what is "arguments from function" :)

    So... if I have a function (i.e. function me($param1, $param2)). It is
    possible to call me($param1)? Like in JavaScript.

  • friglob

    #2
    Re: arguments from function

    iulian.ilea wrote:
    Hey,
    >
    I try to explain what is "arguments from function" :)
    >
    So... if I have a function (i.e. function me($param1, $param2)). It is
    possible to call me($param1)? Like in JavaScript.
    >

    yes, if you have some default $param2 value defined in the function
    predefined argument values always must be after arguments that don`t have predefined values

    function me ( $param1 , $param2 = null ) { ... }
    function me ( $param1 , $param2 = 123 ) { ... }
    function me ( $param1 , $param2 = "word" ) { ... }

    Comment

    • Erwin Moller

      #3
      Re: arguments from function

      iulian.ilea wrote:
      Hey,
      >
      I try to explain what is "arguments from function" :)
      >
      So... if I have a function (i.e. function me($param1, $param2)). It is
      possible to call me($param1)? Like in JavaScript.
      Hi

      I am not 100% sure I understand what you want, but this may be relevant:

      You can use defaultvalues in the function like this:

      function testFunc($arg1, $arg2='test',$a rg3=false){
      ...
      }

      If you call testFunc like this:

      testFunct(23,'J oe');

      In testFunct the following values are used:
      $arg1 <- 23 (passed by calling of the function)
      $arg2 <- 'Joe' (passed by calling of the function)
      $arg3 <- false. Defaults to the value you defined in the function.

      Does that help?

      Regards,
      Erwin Moller

      Comment

      • iulian.ilea

        #4
        Re: arguments from function

        Yes, this is what i want: to call a function (defined with 3 params)
        using only 2, or 1. So i must use some default values. Thank you!
        Erwin Moller wrote:
        iulian.ilea wrote:
        >
        Hey,

        I try to explain what is "arguments from function" :)

        So... if I have a function (i.e. function me($param1, $param2)). It is
        possible to call me($param1)? Like in JavaScript.
        >
        Hi
        >
        I am not 100% sure I understand what you want, but this may be relevant:
        >
        You can use defaultvalues in the function like this:
        >
        function testFunc($arg1, $arg2='test',$a rg3=false){
        ...
        }
        >
        If you call testFunc like this:
        >
        testFunct(23,'J oe');
        >
        In testFunct the following values are used:
        $arg1 <- 23 (passed by calling of the function)
        $arg2 <- 'Joe' (passed by calling of the function)
        $arg3 <- false. Defaults to the value you defined in the function.
        >
        Does that help?
        >
        Regards,
        Erwin Moller

        Comment

        • iulian.ilea

          #5
          Re: arguments from function

          Me, back again with another question about function:
          if I have this function me($param1, $param2=null, $param3,
          $param5=null, $param6=null) how can I found how many parameters are
          send in function when the function is called?
          i.e.: me($masa,null,$ oiu,$doiu,null, $noidoi)
          I want to know if it exists a function that does this.

          Comment

          • Juliette

            #6
            Re: arguments from function

            iulian.ilea wrote:
            Me, back again with another question about function:
            if I have this function me($param1, $param2=null, $param3,
            $param5=null, $param6=null) how can I found how many parameters are
            send in function when the function is called?
            i.e.: me($masa,null,$ oiu,$doiu,null, $noidoi)
            I want to know if it exists a function that does this.
            >
            func_num_args()

            Returns the number of arguments passed to the function


            Comment

            • Alvaro G. Vicario

              #7
              Re: arguments from function

              *** iulian.ilea escribió/wrote (15 Sep 2006 06:56:29 -0700):
              Me, back again with another question about function:
              if I have this function me($param1, $param2=null, $param3,
              $param5=null, $param6=null) how can I found how many parameters are
              send in function when the function is called?
              You cannot do that, not even in JavaScript. There'd be no way to know which
              ones of the provided values match each argument names. From manual:

              "Note that when using default arguments, any defaults should be on the
              right side of any non-default arguments; otherwise, things will not work as
              expected."



              --
              -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
              ++ Mi sitio sobre programación web: http://bits.demogracia.com
              +- Mi web de humor con rayos UVA: http://www.demogracia.com
              --

              Comment

              • iulian.ilea

                #8
                Re: arguments from function

                In JavaScript, if I have func(var1,var2, var3) it is possible to call
                func("valueone" ) or func("valueone" ,"valuetwo") . Ofcourse that value1
                and valuetwo ar assigne to var1 and var2. If a third parameter is sent
                this is assigned to var3.

                Alvaro G. Vicario wrote:
                *** iulian.ilea escribió/wrote (15 Sep 2006 06:56:29 -0700):
                Me, back again with another question about function:
                if I have this function me($param1, $param2=null, $param3,
                $param5=null, $param6=null) how can I found how many parameters are
                send in function when the function is called?
                >
                You cannot do that, not even in JavaScript. There'd be no way to know which
                ones of the provided values match each argument names. From manual:
                >
                "Note that when using default arguments, any defaults should be on the
                right side of any non-default arguments; otherwise, things will not work as
                expected."
                >
                >
                >
                --
                -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
                ++ Mi sitio sobre programación web: http://bits.demogracia.com
                +- Mi web de humor con rayos UVA: http://www.demogracia.com
                --

                Comment

                • Alvaro G. Vicario

                  #9
                  Re: arguments from function

                  *** iulian.ilea escribió/wrote (15 Sep 2006 15:36:17 -0700):
                  In JavaScript, if I have func(var1,var2, var3) it is possible to call
                  func("valueone" ) or func("valueone" ,"valuetwo") . Ofcourse that value1
                  and valuetwo ar assigne to var1 and var2. If a third parameter is sent
                  this is assigned to var3.
                  Right, but you cannot assign var1 and var3 but not var2, as you suggest:

                  function me($param1, $param2=null, $param3,
                  $param5=null, $param6=null)



                  --
                  -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
                  ++ Mi sitio sobre programación web: http://bits.demogracia.com
                  +- Mi web de humor con rayos UVA: http://www.demogracia.com
                  --

                  Comment

                  • iulian.ilea

                    #10
                    Re: arguments from function

                    No, but I can do this: me($p1, null, $p3).

                    Alvaro G. Vicario wrote:
                    *** iulian.ilea escribió/wrote (15 Sep 2006 15:36:17 -0700):
                    In JavaScript, if I have func(var1,var2, var3) it is possible to call
                    func("valueone" ) or func("valueone" ,"valuetwo") . Ofcourse that value1
                    and valuetwo ar assigne to var1 and var2. If a third parameter is sent
                    this is assigned to var3.
                    >
                    Right, but you cannot assign var1 and var3 but not var2, as you suggest:
                    >
                    function me($param1, $param2=null, $param3,
                    $param5=null, $param6=null)
                    >
                    >
                    >
                    --
                    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
                    ++ Mi sitio sobre programación web: http://bits.demogracia.com
                    +- Mi web de humor con rayos UVA: http://www.demogracia.com
                    --

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: arguments from function

                      iulian.ilea wrote:
                      >>*** iulian.ilea escribió/wrote (15 Sep 2006 15:36:17 -0700):
                      >>
                      >>>In JavaScript, if I have func(var1,var2, var3) it is possible to call
                      >>>func("valueo ne") or func("valueone" ,"valuetwo") . Ofcourse that value1
                      >>>and valuetwo ar assigne to var1 and var2. If a third parameter is sent
                      >>>this is assigned to var3.
                      >>
                      >>Right, but you cannot assign var1 and var3 but not var2, as you suggest:
                      >>
                      >>function me($param1, $param2=null, $param3,
                      >>$param5=nul l, $param6=null)
                      >>
                      >>
                      >>
                      >>--
                      >>-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
                      >>++ Mi sitio sobre programación web: http://bits.demogracia.com
                      >>+- Mi web de humor con rayos UVA: http://www.demogracia.com
                      >>--
                      >
                      >
                      No, but I can do this: me($p1, null, $p3).
                      >
                      Alvaro G. Vicario wrote:
                      >
                      (Top posting fixed)

                      Yes, but that passes null as the second argument, which is different
                      from taking the default value for the parameter.

                      P.S. Please don't top post.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      Working...