How can I make an array available to all functions with in a class

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

    How can I make an array available to all functions with in a class

    I unsuccsessfully tried the following:

    class myclass {
    $this->$myvariable[1]=20;
    $this->$myvariable[2]=20;

    function myfuction1{
    print $this->$myvariable[1];
    ;
    }

    function myfuction2{
    print $this->$myvariable[2];

    }


    } //end of myclass;


    Thanks
  • Daniel Tryba

    #2
    Re: How can I make an array available to all functions with in a class

    Perdit <cftranslate@ho tpop.com> wrote:[color=blue]
    > I unsuccsessfully tried the following:[/color]

    No kidding... where did you grt the idea this would work...?
    [color=blue]
    > class myclass {
    > $this->$myvariable[1]=20;
    > $this->$myvariable[2]=20;[/color]
    ^this '$' shouldn't be here (repeated twice below)

    Also you are creating an array "dynamibaly ".
    correct syntax:
    var myvariable=arra y(20,20);

    Please (re)read the classes related documentation on php.net.

    --

    Daniel Tryba

    Comment

    Working...