Manipulating Class variables

Discussion in 'PHP' started by Ikki, Apr 11, 2009.

  1. #1
    Hi guys,

    Hope someone can give me a hand here. Let's imagine we have a class like this one:

    
    class myClass() {
        var $msg = "Hello world";
    
        function someFunction() {
            // do some random stuff here and then...
            $this->msg = $new_msg; // ... change var $msg to what we got in this function...
        }
    
        function yetAnotherFunction() {
            echo $this->msg;
        }
    }
    
    $t = new myClass();
    $t->someFunction();
    $t->yetAnotherFunction(); // this outputs "Hello world", when it should be the new message
    
    PHP:
    ... any ideas? What I'm I doing wrong?

    UPDATE:

    Nevermind. Found out what was wrong and fixed it.
     
    Ikki, Apr 11, 2009 IP
  2. cyno

    cyno Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Because your code looks just fine.
     
    cyno, Apr 13, 2009 IP