<?
class City {
private $length;
function __construct($length) {
$this->length = $length;
}
public function getLength() {
return $this->length;
}
}
class Auto {
private $speed;
function __construct($speed) {
$this->speed = $speed;
}
public function getSpeed() {
return $this->speed;
}
public function howLongToGo($length) {
return $length / $this->speed;
}
public function howLongToGoThrowCity(City $city) {
return $city->getLength() / $this->speed;
}
}
$a = new Auto(20);
$c = new City(100);
print $a->howLongToGo($c->getLength());
// Или так
print $a->howLongToGoThrowCity($c);