Jump to content

$this->result=& $result


ethereal1m

Recommended Posts

Dear all,

I'm reading a tutorial about iterator design pattern on the web but I got stumbled by the following snippet:

class MySQLResultIterator {
    var $result;
    function MySQLResultIterator (& $result) {
        $this->result=& $result;
    }
    function fetch() {
        return mysql_fetch_array($this->result);
    }
    function size() {
        return mysql_num_rows($this->result);
    }
    function reset() {
        return mysql_data_seek($this->result,0);
    }
}

MySQLResultIterator function passes its argument by reference but I don't understand its body part:

$this->result=& $result;

What does it do?

 

Best regards,

ethereal1m

Link to comment
https://forums.phpfreaks.com/topic/185976-this-result-result/
Share on other sites

Yes

$this->result

is the access for the class member variable $result (not local).

 

This statement makes this member variable an alias or reference to the content that the parameter ($result) refers to.

Therefore, inside the method, both $this->result and $result (the parameter) points to the same thing.

After the method exits the member variable $this->result will still point to the same location of whatever variable was passed in as a parameter to the method call.

 

Link to comment
https://forums.phpfreaks.com/topic/185976-this-result-result/#findComment-982180
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.