메뉴 건너뛰기

프로그램언어

2021.03.27 19:03

[PHP기초] 상속기본

조회 수 214 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

 

inheritance.php

<?php
 
//상속
 
class Animal{
 
function run(){
print('runing...<br>');
}
 
function breath(){
print('breathing...<br>');
}
 
}

// human은 Animal 의 메소드(기능)를 상속 받아서(extends) human에 없는 메소드도 사용가능하다.
class human extends Animal{
 
function think(){
print('thinking...<br>');
}
 
function talking(){
print('talking...<br>');
}
 
}
 
//human에 없는 메소드도 사용가능하다.
$human = new Human();
$human ->run();
$human ->think();
 
?>

 

 

inheritance2.php

<?php
 
//이미 php문서에 정의되어있는 클래스
$file = new SplFileObject('data.txt');

//파일을 읽을 것이다.(파일의 사이즈)
//var_dump($file->fread($file->getSize()));
 
//파일의 다시 처음으로 돌아와서 읽기 시작해라
//$file->rewind();
 
//var_dump($file->fread($file->getSize()));

//SplFileObject을 상속하는 MyFileObject 클래스 생성
class MyFileObject extends SplFileObject{
 
//부모의 메소드 상속받아서 자식부분에서 제정의 했다.
function getContents(){
$content = $this->fread($this->getSize());
$this ->rewind();
return $content;
}
}
 
//객체 생성
$file = new MyFileObject('data.txt');
 
//#
//var_dump($file->fread($file->getSize()));
//$file->rewind(); // 이 메소드를 호출해줘야 다시 처음으로 가서 읽는다.
//var_dump($file->fread($file->getSize()));

var_dump($file->getContents());
//getContents안에서 rewind() 해주었기 때문에..여기서 rewind해주지 않아도 된다.
//#1 부분을 반복할 필요가 없음
var_dump($file->getContents());


 
?>

 

 


 


List of Articles
번호 제목 날짜 조회 수
200 phpexcel을 이용한 PHP로 엑셀파일 읽기와 생성 file 2017.03.06 22787
199 phpMyAdmin WebMysql 에 CSV 엑셀 파일 업로드 입력하기 ( Excel / Upload / data / 데이터 / 데이타 ) file 2021.03.25 768
198 php로 db 컨트롤 1 2017.03.06 15769
197 PHP로 Excel 파일 만들기... 2014.02.27 30257
196 PHP로 엑셀 자료 MySQL에 넣기 2017.03.06 17875
195 PHP에서 CSV 파일 export file 2016.04.22 22335
194 PHP에서 Excel 파일을 만들 수 있는 PHPExcel file 2017.03.06 17112
193 PHP에서 PDF파일 생성하기 2014.02.27 32777
192 PHP에서 UTF와 EUC-KR 변환 2019.02.19 1554
191 PHP에서 데이터를 엑셀(Excel)로 저장 2017.02.19 18431
190 PHP에서 모든 세션 정보를 화면에 출력하는 방법 2018.08.29 2694
189 PHP에서 암호화 encrypt 복호화 decrypt 해서 값을 넘기기 2018.02.09 10626
188 PHP에서 자료, 데이터의 타입을 확인하는 방법, gettype() 2018.08.29 2465
187 PHP에서 자바스크립트 값 가져오기 2014.02.27 31635
186 PHP에서 조건문 처리 2015.04.14 22046
185 php에서 체크박스 선택한 것 보여주기 file 2019.01.08 1808
184 PHP에서의 대칭 암호화/복호화 ― 간단한 예제에서 DB 입/출력까지 2018.09.14 3548
183 PHP와 HTML과 자바스크립트의 관계 2021.03.26 311
182 PHP웹 보안 취약점 TOP5(웹해킹) 2023.01.12 293
181 PHP의 유동변수!? - $a1 ~ $a2 같은 형식의 변수를 반복문 돌릴때... 2017.03.06 16610
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved