Think of a class as a car:

The car as a whole is one "object", while it is made up of several smaller
components that serve various "functions".  You can also store different
things in the trunk of the car that will be useful later (these would be the
class variables).

Now lets think of it in programming sense:

PHP allows for object-oriented programming through their class/object
interfaces.  All they really do is serve as a place to dump functions and
variables that are made to work with one another directly, and in many cases
to prevent non-related functions and processes from accessing their data
directly (although this is one of the best things about Object-Oriented
Programing, PHP hasn't entirely implemented it yet).

A simple class:

class car {
    var $color;
    var $doors;
    var $year;
    var $model;
    var $fuel;

    function car() {
        $doors = "4";
        $year = "2001";
        $model = "PHP Class Car";
    }

    function addFuel($gallons) {
        $this->fuel += $gallons;
    }

    var paintCar($newcolor) {
        $this->color = $newcolor;
    }
}

The class encapsulates all this information.  To use this stuff you need to
create a variable of type car:

$myCar = new car;

Doing this automatically calls the "constructor" function if one is present.
The constructor is a function with the same name as the class (this rule
varies a bit depending on your version of PHP; read the manual for details).
In the constructor, certain variables are given default values and certain
functions can be called if needed.

After that you can access variable data using $myCar->[variable name].
Functions are called the same way: $myCar->myFunction($myArgs);

Those are the basics.  There's a great deal more to learn about OOP.  If you
really want to learn about OOP, get a book on C, C++ or Java.  These are
probably the three best implementations of OOP (and it really originated in
its current form with C++).

Mike Frazer



"Jack" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Dear all
> I'm fresh on PHP, there is a question which i don't understand , even i
had
> read the book about PHP.
> There is a Class and object in PHP, but i don't quite understand what is
> that for.
> I had look at some of the Example in PHP.net and i know most of it, but
> there is a operator :
> $this->edible = $edible;
> What is the "$this -> " stand for?
>
> Could someone please tell me more???
> Thx
>
> jack
> [EMAIL PROTECTED]
>
>



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to