Jump to content

[SOLVED] Simple PHP Qustion


ashton321

Recommended Posts

Im new to PHP and can write basic scripts but im starting to learn functions and classes and i guess the problem for me lies in the $this.  I have been doing a little reading like 

class Cart {
    var $todays_date;
    var $name;
    var $owner;
    var $items = array("VCR", "TV");

    function Cart() {
        $this->todays_date = date("Y-m-d");
        $this->name = $GLOBALS['firstname'];
        /* etc. . . */
    }
}

So the this means for the items in the class above the function are being set?

A class is an object template. When you instantiate an object, eg;

 

$obj = new myclass;

 

You create an object of the type myclass (in the given example).

 

Now, within your class template $this is used to refer to the object that will be created once your class has been instantiated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.