ejgeske commented on a Page, Building a Parent/Child Category Structure  -  Dec 05, 2008

in the following example, i will assign some variables that belong to a class. But are assigned inside one of the function/methods. If you only assign it as $example and not as $this->example, it does not assign that variable to the entire class, only in that method/function.

class myClass
{
var $example;
var $example2;

function say_what()
{
    $example = 'Hi';
    $this->example2 = 'Hi again';

    echo '$example: '.$example."<br/>";
    echo '$example2: '.$example2."<br/>";
    echo '$this->example: '.$this->example."<br/>";
    echo '$this->example2: '.$this->example2."<br/>";
}
function say_again()
{
    echo '$example: '.$example."<br/>";
    echo '$example2: '.$example2."<br/>";
    echo '$this->example: '.$this->example."<br/>";
    echo '$this->example2: '.$this->example2."<br/>";
}

}

$convo = new myClass();
$convo->say_what();
$convo->say_again();


PRINT OUT

// this is $convo->say_what();
$example: Hi
$example2: //blank
$this->example: //blank
$this->example2: Hi again

// this is $convo->say_again();
$example: //blank
$example2: //blank
$this->example: //blank
$this->example2: Hi again // only this one assigned to class shows.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.