Results 1 to 3 of 3

Thread: Help Understanding PHP Code

  1. #1
    Join Date
    Sep 2004

    Help Understanding PHP Code

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

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



  2. #2
    Join Date
    Aug 2004
    $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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Jul 2004
    Rhode Island
    $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!


    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