mcloan Posted November 20, 2006 Share Posted November 20, 2006 Can someone tell me what the $this->content of the code below means? $lines = preg_split('/\r?\n/', $this->content); Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/27876-this-help/ Share on other sites More sharing options...
CheesierAngel Posted November 20, 2006 Share Posted November 20, 2006 $this is mostly used to specify the current object/class data. Quote Link to comment https://forums.phpfreaks.com/topic/27876-this-help/#findComment-127467 Share on other sites More sharing options...
.josh Posted November 20, 2006 Share Posted November 20, 2006 example:[code]<?php class someClass { var content; function doSomething() { $lines = preg_split('/\r?\n/', $this->content); } // end function doSomething } // end class someClass$someThing = new someClass;//these 2 content variables are 2 different variables with 2 different scopes$someThing->content = "anything";$content = "blah";?>[/code]$this->content specifies the $content variable in the class someClass. Your function doSomething is inside that class, so it's like saying "okay I need the variable $content. Which one? [i]this[/i] one, right here next to me. Oh okay, the one that holds 'anything' not that other one that holds 'blah' "when you are outside of the class, you can refer to it as the object->property, like where i had $someThing->content. When you are working inside the class, you can use $this->property, and it knows to refer to the property inside that class. Quote Link to comment https://forums.phpfreaks.com/topic/27876-this-help/#findComment-127471 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.