模拟的钓鱼类,纯粹是秀一把,^_^

361 查看

<?php

class fish {

  public function eating($food) {
      echo "Fish is eating " . $food;
  }

  public function swim() {
      echo "Fish is swimming!";
  }

}

class People {

  private $fish;
  private $food;

  public function __construct(fish $fish, $food) {
      $this->fish = $fish;
      $this->food = $food;
  }

  public function fishing() {
      $this->fish->eating($this->food);
  }

  public function getFish() {
      echo "put up the fish!";
  }

}

$jiyu = new fish();
$jiyu->swim();
echo '<hr/>';
$p = new People($jiyu, '蚯蚓');
$p->fishing();
echo "<hr/>";
$p->getFish();