public function actionIndex()
 {
     echo "<h1>All cars</h1>";
     $cars = Car::model()->findAll();
     foreach ($cars as $car) {
         // Each car can be of class Car, SportCar or FamilyCar
         echo get_class($car) . ' ' . $car->name . "<br />";
     }
     echo "<h1>Sport cars only</h1>";
     $sportCars = SportCar::model()->findAll();
     foreach ($sportCars as $car) {
         // Each car should be SportCar
         echo get_class($car) . ' ' . $car->name . "<br />";
     }
 }
예제 #2
0
<?php

include_once "Car.php";
include_once "SportCar.php";
include_once "Engine.php";
$myCar = new Car("Toyota", "Corolla", "zielony", "sedan");
$otherCar = new Car("Volkswagen", "Passat", "biały", "combi");
//echo $myCar->helloCar();
//echo $otherCar->helloCar();
//echo $otherCar->getColor();
//$otherCar->setColor("niebieski");
//echo $otherCar->helloCar();
function theCar($car)
{
    return "Witaj! To ja Twój samochód: " . $car->getColor() . " " . $car->getBrand() . " " . $car->getModel() . " " . $car->getType() . "\n";
}
//echo theCar($otherCar);
$sportCar = new SportCar();
$sportCar->tuning(new Engine(100));
echo $sportCar->getParams() . "\n";
echo "Zmiana silnika \n";
$sportCar->tuning(new Engine(300));
echo $sportCar->getParams() . "\n";