OOP(Object-Oriented Programming - 객체지향 프로그램) 만들기

클래스를 이용하여 간단한 php oop 도 만들어 보자

class MyOop {
  private $animal = '';
  private $where = '';
  private $doing = '';

  public function animal($str) {
    $this->animal = $str;
    return $this;
  }

  public function where($str) {
    $this->where = $str;
    return $this;
  }

  public function doing($str) {
    $this->doing = $str;
    return $this;
  }

  public function print() {
    return 'The '.$this->animal.' is '.$this->doing.'ing on the '. $this->where ;
  }
}
class OOPController {
  
  public function create(){
    $oop = new MyOop();
    $str = $oop->animal('cat')->where('table')->doing('eat')->print();
    print_r($str);

  }
}
평점을 남겨주세요
평점 : 2.5
총 투표수 : 1