Cobby Posted June 12, 2007 Share Posted June 12, 2007 Hi all, I knew a bit of PHP, and have decided to learn OOP. I have read through a few tutorials, and I am just wonder what -> means. I usually see some thing like this ... $this->$variable ... Thanks, Cobby Link to comment https://forums.phpfreaks.com/topic/55241-solved-n00b-queastion-what-does-mean/ Share on other sites More sharing options...
Full-Demon Posted June 12, 2007 Share Posted June 12, 2007 In a class you have variable and functions. By calling $this->[function or var(without $)] inside a class, it will call the var or func that is defined in that class. Use [any class name]->[func or var] in general. So replace $this by a class var (= $classvar = new yourclassname;) to call a func or var from another class. Can be in or outside a class. FD Link to comment https://forums.phpfreaks.com/topic/55241-solved-n00b-queastion-what-does-mean/#findComment-273041 Share on other sites More sharing options...
Cobby Posted June 12, 2007 Author Share Posted June 12, 2007 Oh ok, So, just for my ease, I will compare it to a URL. '$this->index' would be like http://localhost/index and 'url->index' would be like http://53.156.23.4/index (just a random IP) Well thats how I understand it anyway, is that right? Sorry for the silly metaphor Cheers, Cobby Link to comment https://forums.phpfreaks.com/topic/55241-solved-n00b-queastion-what-does-mean/#findComment-273050 Share on other sites More sharing options...
emehrkay Posted June 12, 2007 Share Posted June 12, 2007 class test{ public $_x; public function func1(){ echo $this->func2(); } public function func2(){ return $this->_x = 3; } } $f = new test(); $f->func1(); // echo 3 echo $f->func2(); //echo 3 as well -> basically means use. so '$this' means this object. so $this->_x = 3; means set this ojbect's property _x to 3. and $this->func2(); means call method func2() inside of this object. its a pretty simple concept once you work with it for a while Link to comment https://forums.phpfreaks.com/topic/55241-solved-n00b-queastion-what-does-mean/#findComment-273155 Share on other sites More sharing options...
dStreSd Posted June 12, 2007 Share Posted June 12, 2007 In programming theory the "arrow" simple points to a member of an object, to really understand it you have to understand objects and classes first. The previous posters' reply should be an adequate introduction. Link to comment https://forums.phpfreaks.com/topic/55241-solved-n00b-queastion-what-does-mean/#findComment-273391 Share on other sites More sharing options...
Cobby Posted June 12, 2007 Author Share Posted June 12, 2007 Thanks for your help guys. I found out it was called the arrow operator, so I googled that and I came up with few sites, but not the PHP manual. I suppose I understand now, the more OOP I do the more clear it will become. Thanks, Cobby Link to comment https://forums.phpfreaks.com/topic/55241-solved-n00b-queastion-what-does-mean/#findComment-273498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.