$this variable reference question

From: Date: Sat, 03 Apr 2004 00:03:47 +0000
Subject: $this variable reference question
Groups: php.general 
Request: Send a blank email to php-general+get-182216@lists.php.net to get a copy of this message
I was trying to bend my mind around the concept of the reference operator (&) today and came across an article at http://www.onlamp.com/pub/a/php/2002/09/12/php_foundations.html where the author gave the following example: <?php
    class test {
        function test($val) {
            global $myref;
            $myref = &$this;
            $this->value = $val;
        }
        function printval() {
            echo "The value of this class is '{$this->value}' <br>";
        }
        function setval($val) {
            $this->value = $val;
        }
    }
?> My question is actually regarding the line "$myref = &$this;". The author states that this is a reference to the class/object itself. Isn't this like saying outside the class "$myref =& new test;"? What would be the point of referring to itself inside the class in this manner? Thanks for your help in advance! -Adam Reiswig

« previous php.general (#182216) next »