example OOP wapcreate.com is pure OOP and is built upon MVC architecture
PHP Code:
class Car {
private $carname;
private $caryear;
public object;
public function __construct($carname, $caryear)
{
self::setName($carname); //this could also be done using $this->setName($carname) or Car::setName($carname)
self::setYear($caryear);
}
public function setYear($y)
{
$this->caryear = $y;
}
public function setName($n)
{
$this->carname = $n;
}
public function getName()
{
return $this->carname;
}
public function getYear()
{
return $this->caryear;
}
}; // the semicolon is not needed here
usage of this class will be
$car = new Car("Lamboginy", "2010");
you can now use the get methods to access properties of this class
like if you wanted to print the year of the car it will be like
echo $car->getYear(); will print 2010;
you can also have objects within other objects like
$car->object = new Car("BMW", "2011");
echo $car->object->getName(); will print BMW
Comment