Php-function-get-parent-class
提供:Dev Guides
PHP-関数get_parent_class()
構文
get_parent_class ( $object );
定義と使い方
オブジェクトまたはクラスの親クラス名を取得します。
パラメーター
Sr.No | Parameter & Description |
---|---|
1 |
object(Required) テストされたオブジェクトまたはクラス名。 |
戻り値
現在のスクリプトで宣言されたクラスの名前の配列を返します。
例
以下は、この機能の使用法です-
<?php
class f1 {
function f1() {
//implements some logic
}
}
class child extends f1 {
function child() {
echo "I'm " , get_parent_class($this) , "'s son \n";
}
}
class child2 extends f1 {
function child2() {
echo "I'm " , get_parent_class('child2') , "'s son too \n";
}
}
$foo = new child();
$bar = new child2();
?>
それは次の結果を生成します-
I'm f1's son
I'm f1's son too