Passing an Array to a Class

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

    Passing an Array to a Class

    When I try to pass an array to a class the program hangs up.

    php4, windows xp pro

    This debug is going real slow due to having to reboot after every test
    run.

    Any help would be greatly appreciated!

    the function in the calling program:

    $new_session->set_serial_num bers('$serial_n umber_array');

    usage in the class:

    var $sn_array=array ();

    function set_serial_numb ers($serial_num ber_array)
    {$this->sn_array=$seri al_number_array ;}

    for ($q=0;$q<count( $this->sn_array);$q )
    {echo $this->sn_array{$q}." <br>";}

  • Erwin Moller

    #2
    Re: Passing an Array to a Class

    Bob wrote:

    Hi Bob
    [color=blue]
    > $new_session->set_serial_num bers('$serial_n umber_array');[/color]

    Should that be:
    $new_session->set_serial_num bers("$serial_n umber_array");
    ???

    You use ' and a variable inside ' do not get replace by its value.
    It does inside "

    $a = "hello";
    echo "$a"; // output: hello
    echo '$a'; // output: $a

    not sure if that is the problem though, but it looks like a mistake.

    Good luck,
    Erwin Moller

    Comment

    • Bob

      #3
      Re: Passing an Array to a Class

      No that is not it.
      I just tried it, and I had to "halt the process".
      Thanks for the try!
      Bob

      Comment

      • Pedro Graca

        #4
        Re: Passing an Array to a Class

        Bob wrote:[color=blue]
        > When I try to pass an array to a class the program hangs up.
        >[/color]
        <snip>[color=blue]
        >
        > for ($q=0;$q<count( $this->sn_array);$q )
        > {echo $this->sn_array{$q}." <br>";}[/color]

        Where is $q changed in this loop?

        --
        Mail to my "From:" address is readable by all at http://www.dodgeit.com/
        == ** ## !! ------------------------------------------------ !! ## ** ==
        TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
        may bypass my spam filter. If it does, I may reply from another address!

        Comment

        • Andrew

          #5
          Re: Passing an Array to a Class

          Your problem is here:
          $new_session->set_serial_num bers('$serial_n umber_array');

          if you are passing an array you needn't use any form of quotes! This
          will actually pass the string "array()"

          Comment

          • Bob

            #6
            Re: Passing an Array to a Class

            That is it!
            Bless your soul!
            I was looking in the wrong place.
            Many thanks.
            Bob

            Comment

            Working...