호환성
PHP4 >= 4.0b2
기능
객체나 클래스의 부모클래스명을 반환
형식
string get_parent_class (mixed obj)
설명
obj가 객체이면 인스턴스화할 때 사용된 클래스의 부모클래스명을 반환합니다. obj가 문자열이면, 그 이름을 갖는 클래스의 부모클래스명을 반환합니다. 이 기능은 PHP 4.0.5에서 추가되었습니다.
[code php;gutter:false]
<?php
// base class with member properties and methods
class Vegetable {
var $edible;
var $color;
function Vegetable( $edible, $color="green" ) {
$this->edible = $edible;
$this->color = $color;
}
function is_edible() {
return $this->edible;
}
function what_color() {
return $this->color;
}
} // end of class Vegetable
// extends the base class
class Spinach extends Vegetable {
var $cooked = false;
function Spinach() {
$this->Vegetable( true, "green" );
}
function cook_it() {
$this->cooked = true;
}
function is_cooked() {
return $this->cooked;
}
} // end of class Spinach
$obj = new Spinach;
echo "객체 \$obj를 생성했던 클래스는 ".get_class($obj)."이며,
그 부모클래스는 ".get_parent_class($obj)."입니다.";
?> [/code]
// base class with member properties and methods
class Vegetable {
var $edible;
var $color;
function Vegetable( $edible, $color="green" ) {
$this->edible = $edible;
$this->color = $color;
}
function is_edible() {
return $this->edible;
}
function what_color() {
return $this->color;
}
} // end of class Vegetable
// extends the base class
class Spinach extends Vegetable {
var $cooked = false;
function Spinach() {
$this->Vegetable( true, "green" );
}
function cook_it() {
$this->cooked = true;
}
function is_cooked() {
return $this->cooked;
}
} // end of class Spinach
$obj = new Spinach;
echo "객체 \$obj를 생성했던 클래스는 ".get_class($obj)."이며,
그 부모클래스는 ".get_parent_class($obj)."입니다.";
?> [/code]
< 예제 소스 >
객체 $obj를 생성했던 클래스는 spinach이며, 그 부모클래스는 vegetable입니다.
< 실행 결과 >
참고
get_class(), is_subclass_of()
'phpclass > 클래스활용' 카테고리의 다른 글
{클래스&객체함수}13.is_subclass_of (0) | 2000.10.10 |
---|---|
{클래스&객체함수}12.is_a (0) | 2000.10.10 |
{클래스&객체함수}10.get_object_vars (0) | 2000.10.10 |
{클래스&객체함수}09.get_declared_classes (0) | 2000.10.10 |
{클래스&객체함수}08.get_class_vars (0) | 2000.10.10 |