Em mới học php và bị mắc ở phần class, gọi đến các member function,…
Em muốn tạo 1 thuộc tính $reservation là mảng có kiểu là class Reservation trong class Room. Hàm addReservation và removeReservation để thêm, xóa 1 phần tử của $reservation.
- Code lỗi ở 3 dòng bên dưới
class Room implements iReservable{
    protected $roomtype, $hasRestroom, $hasBalcony, $bedCount, $roomNumber, $extras;
    protected $reservation = new Reservation(); //Lỗi
    function createRoom($roomtype, $hasRestroom, $hasBalcony, $bedCount, $extras){
        $this->roomtype = $roomtype;
        $this->hasRestroom = $hasRestroom;
        $this->hasBalcony = $hasBalcony;
        $this->bedCount = $bedCount;
        $this->extras = $extras;
    }
    function addReservation($reservation){
       $this->reservation->add($reservation); //Lỗi
    }
    function removeReservation($reservation){
        $index = array_search($reservation, $this->reservation); //Lỗi
        unset($this->reservation[$index]);
    }
    function getReservation(){
        return $this->reservation;
    }
    function getRoomNumber(){
        return $this->roomNumber;
    }
}
 
      
     
  83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?
    83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?