Tuesday, December 21, 2010

PHP Objects

PHP supports the creation of classes and objects. A class can be created as follows:
class Auto {
var $position = 1;

function move ($distance)
{
$this->position += $distance;
}

function report()
{
echo "Position = " . (string) $this->position . "<BR>";
}
}
The object may be created as follows:
$Car = new Auto;
Moving the car can be done with the following line:
$Car->move(4);

No comments:

Post a Comment