ethereal1m Posted December 22, 2009 Share Posted December 22, 2009 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 More sharing options...
cags Posted December 22, 2009 Share Posted December 22, 2009 I've never work with ByRef values in PHP, but I would assume it makes the local variable $result a reference to $result the variable passed in. Link to comment https://forums.phpfreaks.com/topic/185976-this-result-result/#findComment-982178 Share on other sites More sharing options...
jamesm6162 Posted December 22, 2009 Share Posted December 22, 2009 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 More sharing options...
ethereal1m Posted December 22, 2009 Author Share Posted December 22, 2009 great! thanks Link to comment https://forums.phpfreaks.com/topic/185976-this-result-result/#findComment-982197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.