Passing to a function...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randell D.

    Passing to a function...


    Folks,

    I have created a function that accepts a dynamic number of arguements
    and while it works, I'm wondering if I am passing it data in a correct
    format...

    I call the function as so

    myFunction($myA rray, a, b ,c);

    a, b and c are elements in $myArray... Is the above syntax incorrect?
    Should I use

    myFunction($myA rray, "a", "b" ,"c");

    in order to be more correct?

    I'm afraid that while it works now, some minor bug fix later might prove
    to be a show stopper for me...

    All help,via the newsgroup (for all to learn) is greatly appreciated,

    randelld
  • Michael Fesser

    #2
    Re: Passing to a function...

    .oO(Randell D.)
    [color=blue]
    >I have created a function that accepts a dynamic number of arguements
    >and while it works, I'm wondering if I am passing it data in a correct
    >format...
    >
    >I call the function as so
    >
    > myFunction($myA rray, a, b ,c);
    >
    >a, b and c are elements in $myArray... Is the above syntax incorrect?[/color]

    Why not simply test it? The above will be correct in at least one case.
    [color=blue]
    >Should I use
    >
    > myFunction($myA rray, "a", "b" ,"c");
    >
    >in order to be more correct?[/color]

    Make sure your error_reporting is set to E_ALL in your php.ini, then
    test both variants to see the difference.

    Micha

    Comment

    • Alvaro G Vicario

      #3
      Re: Passing to a function...

      *** Randell D. wrote/escribió (Tue, 22 Feb 2005 01:33:14 GMT):[color=blue]
      > myFunction($myA rray, a, b ,c);
      >
      > a, b and c are elements in $myArray... Is the above syntax incorrect?
      > Should I use
      >
      > myFunction($myA rray, "a", "b" ,"c");
      >
      > in order to be more correct?[/color]

      Check the "Language Reference" chapter in PHP manual, it provides a quite
      comprehensive insight on PHP syntax.

      As for your questions:

      foo is a constant: define('foo', 'Hello'); echo foo;
      "foo" is a string: echo "foo";
      $foo is a variable: $foo='Hello'; echo $foo;
      foo() is a function: function foo(){return 'Hello';} echo foo();


      --
      -- Álvaro G. Vicario - Burgos, Spain
      -- Thank you for not e-mailing me your questions
      --

      Comment

      • Randell D.

        #4
        Re: Passing to a function...

        Michael Fesser wrote:[color=blue]
        > .oO(Randell D.)
        >
        >[color=green]
        >>I have created a function that accepts a dynamic number of arguements
        >>and while it works, I'm wondering if I am passing it data in a correct
        >>format...
        >>
        >>I call the function as so
        >>
        >> myFunction($myA rray, a, b ,c);
        >>
        >>a, b and c are elements in $myArray... Is the above syntax incorrect?[/color]
        >
        >
        > Why not simply test it? The above will be correct in at least one case.
        >
        >[color=green]
        >>Should I use
        >>
        >> myFunction($myA rray, "a", "b" ,"c");
        >>
        >>in order to be more correct?[/color]
        >
        >
        > Make sure your error_reporting is set to E_ALL in your php.ini, then
        > test both variants to see the difference.
        >
        > Micha[/color]

        Both work - but I was wondering if one was more correct/legal than the
        other...

        Thanks though,
        randelld

        Comment

        • Randell D.

          #5
          Re: Passing to a function...

          Alvaro G Vicario wrote:
          [color=blue]
          > *** Randell D. wrote/escribió (Tue, 22 Feb 2005 01:33:14 GMT):
          >[color=green]
          >> myFunction($myA rray, a, b ,c);
          >>
          >>a, b and c are elements in $myArray... Is the above syntax incorrect?
          >>Should I use
          >>
          >> myFunction($myA rray, "a", "b" ,"c");
          >>
          >>in order to be more correct?[/color]
          >
          >
          > Check the "Language Reference" chapter in PHP manual, it provides a quite
          > comprehensive insight on PHP syntax.
          >
          > As for your questions:
          >
          > foo is a constant: define('foo', 'Hello'); echo foo;
          > "foo" is a string: echo "foo";
          > $foo is a variable: $foo='Hello'; echo $foo;
          > foo() is a function: function foo(){return 'Hello';} echo foo();
          >
          >[/color]

          Thanks... I'll check out the PHP manual - I suppose my question should
          have asked if my former method was attempting to pass the constants a, b
          or c, as opposed to the values - I wanted the values to be passed and
          both methods give the same result - however I was unsure if there was
          one method more legal/correct than the other.

          Thanks
          randelld

          Comment

          • Michael Fesser

            #6
            Re: Passing to a function...

            .oO(Randell D.)
            [color=blue]
            >Thanks... I'll check out the PHP manual - I suppose my question should
            >have asked if my former method was attempting to pass the constants a, b
            >or c, as opposed to the values -[/color]

            Yep.
            [color=blue]
            >I wanted the values to be passed and
            >both methods give the same result - however I was unsure if there was
            >one method more legal/correct than the other.[/color]

            As said before - set error_reporting to E_ALL, then the first variant
            will show three notices unless the constants a, b and c are defined.

            Micha

            Comment

            • Alvaro G Vicario

              #7
              Re: Passing to a function...

              *** Randell D. wrote/escribió (Tue, 22 Feb 2005 22:01:26 GMT):[color=blue]
              > Thanks... I'll check out the PHP manual - I suppose my question should
              > have asked if my former method was attempting to pass the constants a, b
              > or c, as opposed to the values - I wanted the values to be passed and
              > both methods give the same result - however I was unsure if there was
              > one method more legal/correct than the other.[/color]

              For some weird reason, PHP handles undefined constants as if they were
              strings containing the constant name.

              echo THIS_CONSTANT_I S_UNDEFINED; // Prints: THIS_CONSTANT_I S_UNDEFINED


              --
              -- Álvaro G. Vicario - Burgos, Spain
              -- Thank you for not e-mailing me your questions
              --

              Comment

              • Michael Fesser

                #8
                Re: Passing to a function...

                .oO(Alvaro G Vicario)
                [color=blue]
                >For some weird reason, PHP handles undefined constants as if they were
                >strings containing the constant name.[/color]

                It's not weird.
                [color=blue]
                >echo THIS_CONSTANT_I S_UNDEFINED; // Prints: THIS_CONSTANT_I S_UNDEFINED[/color]

                Notice: Use of undefined constant THIS_CONSTANT_I S_UNDEFINED - assumed
                'THIS_CONSTANT_ IS_UNDEFINED' in [...] on line [...]

                Micha

                Comment

                • Alvaro G Vicario

                  #9
                  Re: Passing to a function...

                  *** Michael Fesser wrote/escribió (Wed, 23 Feb 2005 19:20:30 +0100):[color=blue][color=green]
                  >>For some weird reason, PHP handles undefined constants as if they were
                  >>strings containing the constant name.[/color]
                  >
                  > It's not weird.[/color]

                  Anyway, I can't understand the purpose. Why only in constants and not in
                  variables?

                  --
                  -- Álvaro G. Vicario - Burgos, Spain
                  -- Thank you for not e-mailing me your questions
                  --

                  Comment

                  • Matt Mitchell

                    #10
                    Re: Passing to a function...

                    "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
                    message news:3nehvij6rv g9.ub5cge26ueus $.dlg@40tude.ne t...
                    : *** Michael Fesser wrote/escribió (Wed, 23 Feb 2005 19:20:30 +0100):
                    : >>For some weird reason, PHP handles undefined constants as if they were
                    : >>strings containing the constant name.
                    : >
                    : > It's not weird.
                    :
                    : Anyway, I can't understand the purpose. Why only in constants and not in
                    : variables?
                    :

                    Probably because it's reminiscent of Perl's handling of barewords?

                    Because of sunspots?

                    A far more pertinent question, though, is why somebody would want to use
                    uninitialised constants in their code...


                    Comment

                    Working...