SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot willmoss's Avatar
    Join Date
    Apr 2002
    Location
    London, England
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with passing an array to a class

    hey everyone,

    can someone help me? this is a really stupid issue but it's driving me mad!

    i am passing an array to a function in a class. the function is called setColumns:

    PHP Code:
      function setColumns($columns) {
      
      echo 
    is_array($columns);
      
    $this->$columns $columns;    
       echo 
    is_array($this->columns);
      
      } 
    ... and sets the value of $this->columns to whatever is passed to the function.

    in the script that uses the class, I am calling the function as follows:

    PHP Code:
     $columns = array ( => "title" => "url" );
     
    $product->setColumns$columns ); 
    when I pass an array to setcolumns, the first call to is_array returns true but the second one returns false.. ie. $columns is an array but $this->columns isn't.

    what is going on! how can I set $this->columns as a copy of the $columns array?

    thanks!

  2. #2
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use $this->columns, not $this->$columns :-)

  3. #3
    SitePoint Zealot willmoss's Avatar
    Join Date
    Apr 2002
    Location
    London, England
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i thought it would be something really stupid like that. thanks sorccu


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •