[php] 객체지향 프로그램 만들기 updated_at: 2024-12-15 04:04

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

PHP에서도 클래스를 이용한 객체지향 프로그램이 기능하다.

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 subfunc($callback)
  {
    $otherclass = new Dataset($this);;
    $otherclas->index =  count($$otherclass->group);
    $callback($otherclass);
    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')
      ->subfunc(function($dataset) use($data) {
        $dataset->setData(array_column($data , 'count'));
        $dataset->setdefaultColor();
      })
      ->print();
    print_r($str);

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

질문 및 답글