www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help Understanding PHP Code

  1. #1
    Join Date
    Sep 2004
    Posts
    36

    Help Understanding PHP Code

    Can someone please explain how the following variables are being used?

    Code:
    $this->contents = array();
    $this->total = 0;
    $this->weight = 0;
    $this->content_type = false;
    Basically I would like to know what the following code does:

    Code:
     $this->
    Thanks,

    Jeff

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,923
    $this is a special variable within a class definition, referring to "this instantiation of this class". So $this->some_name is either an attribute (i.e.: variable) of this class, or a method (i.e.: function) of this class. For more info: PHP 4 Classes or PHP 5 Classes.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2004
    Location
    Rhode Island
    Posts
    190
    $this->methodOrProperty references a method or property of the current instance of an object in PHP.

    PHP: Classes and Objects (PHP 4)
    PHP: Classes and Objects (PHP 5)

    In all of the lines of code, contents, total, weight, and content_type are all properties of an object. $this is a reference to the current instance of an object being operated upon.

    To determine what type of object you're working in, look for the opening line that says something like...

    PHP Code:
    class ClassName 
    Hope it helps!

    -Matt

    PS, NogDog, apparently we think alike I started typing mine before yours was posted.
    Matt Pat
    The World's Best Web Browser (Windows, Linux, and Mac): Get Firefox!
    My website: http://www.mattpat.net
    Control iTunes Remotely: TuneConnect

    "What's accepted is not always what's right."
    Look it up: What's the longest word in the English language?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles