Apr 20, 2008

PHP Objects

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

Popular Posts