Jump to content

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/27876-this-help/#findComment-127471
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.