bishup Posted May 4, 2006 Share Posted May 4, 2006 When variables are being declaired and manipulated I am running in to this structure of code.$this->variable_name = 'homey the clown'; (ex.)What is the $this used for and what does it do, i have no clue...Might as well through this out there also, what is...$this->variable .= 'something to have';Appreachiate the help / insight Quote Link to comment https://forums.phpfreaks.com/topic/9062-simple-question-just-wondering/ Share on other sites More sharing options...
ober Posted May 4, 2006 Share Posted May 4, 2006 $this is a keyword within a class that refers to the classes global variables.$this->variable_name = "x"; will set the class's variable equal to x.The .= is an append. It will add whatever is past the equals sign to the current string instead of replacing it. Quote Link to comment https://forums.phpfreaks.com/topic/9062-simple-question-just-wondering/#findComment-33336 Share on other sites More sharing options...
bishup Posted May 4, 2006 Author Share Posted May 4, 2006 [!--quoteo(post=371289:date=May 4 2006, 11:28 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 4 2006, 11:28 AM) [snapback]371289[/snapback][/div][div class=\'quotemain\'][!--quotec--]$this is a keyword within a class that refers to the classes global variables.$this->variable_name = "x"; will set the class's variable equal to x.The .= is an append. It will add whatever is past the equals sign to the current string instead of replacing it.[/quote]Thank you, that is what i needed to know!that make a lot more sence when i read through other code. Quote Link to comment https://forums.phpfreaks.com/topic/9062-simple-question-just-wondering/#findComment-33351 Share on other sites More sharing options...
wildteen88 Posted May 4, 2006 Share Posted May 4, 2006 Also note that $this-> is used to call internal functions within the class too aswell as variables. Example:[code]<?phpclass foo { function foo() { //call bar(); $this->bar(); } function bar() { echo "bar() was called internally!"; }}$foo = new foo;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9062-simple-question-just-wondering/#findComment-33358 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.