45 lines
664 B
PHP
45 lines
664 B
PHP
<?php
|
|
|
|
class Pet {
|
|
public $name;
|
|
public $isRunning = false;
|
|
|
|
public function run()
|
|
{
|
|
$this->isRunning = true;
|
|
return $this->name . ' is running';
|
|
}
|
|
}
|
|
|
|
class Dog extends Pet {
|
|
protected $currentChaseTarget;
|
|
|
|
public function chase(Pet $chaseTarget)
|
|
{
|
|
$this->isRunning = true;
|
|
$this->currentChaseTarget = $chaseTarget;
|
|
$this->currentChaseTarget->run();
|
|
|
|
return $this->name . ' is chasing ' . $chaseTarget->name;
|
|
}
|
|
}
|
|
|
|
$cat = new Pet();
|
|
$cat->name = 'Felix';
|
|
|
|
var_dump($cat);
|
|
|
|
$cat->run();
|
|
|
|
var_dump($cat);
|
|
|
|
$dog = new Dog();
|
|
$dog->name = 'Fido';
|
|
|
|
var_dump($dog);
|
|
|
|
var_dump($dog->chase($cat));
|
|
|
|
var_dump($dog);
|
|
var_dump($cat);
|