class Child {
var $age = 5;
function eat() {
echo "Tasty!";
}
function sex() {
echo "Pleasantly!";
}
function getAge() {
return $this->age;
}
}
class Nanny {
var $child;
var $nanny_age = 40;
function Nanny($child) {
$this->child = $child;
}
function eat() {
$this->cooking();
$this->child->eat();
}
function sex() {
if (!$this->isLegalAge($this->child->getAge())) {
echo "Oh, no baby!";
} else {
echo "Foreplay... Condom?";
$this->child->sex();
}
}
function isLegalAge($age) {
if ($age <= $this->nanny_age) {
return false;
}
return true;
}
function cooking(){
echo "Pap...";
}
}
$nanny =& new Nanny(new Child());
$nanny->eat();
$nanny->sex();