thenewperson Posted November 4, 2009 Share Posted November 4, 2009 I think these this is a pointer "->" my question is what does it do i often see it in open sources like $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error()); $this -> num_members = -1; so on.... i see $this -> used so many times in same source so bit confued my guess is their storing bunch of values into $this but i dont understand the advantage of that Quote Link to comment https://forums.phpfreaks.com/topic/180213-solved-question-on-php-pointers/ Share on other sites More sharing options...
thenewperson Posted November 4, 2009 Author Share Posted November 4, 2009 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/180213-solved-question-on-php-pointers/#findComment-950702 Share on other sites More sharing options...
Alex Posted November 4, 2009 Share Posted November 4, 2009 -> is used to access methods and properties of an object in PHP OOP. There are plenty of examples there to help you understand. The reserved variable $this is used to access methods and properties of a class from within one of it's methods. Quote Link to comment https://forums.phpfreaks.com/topic/180213-solved-question-on-php-pointers/#findComment-950704 Share on other sites More sharing options...
mikesta707 Posted November 4, 2009 Share Posted November 4, 2009 the $this->whatever syntax is PHP's way of accessing class variables/methods within a class. PHP doesn't have a pointer type. in C++ it is similar to the this->whatever syntax, but in PHP you always must use $this->whatever when accessing attributes/methods inside a class, where in C++ you don't have to. It differs where in C++ this refers to the location in memory that the object resides (basically it is a pointer to itself) while in PHP it simply means it is referencing attributes or whatever in the class Quote Link to comment https://forums.phpfreaks.com/topic/180213-solved-question-on-php-pointers/#findComment-950705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.