PHP 快速導覽 - 核心延伸函數 類別、物件相關 get_parent_class()

內建函數 (function) get_parent_class() 取得物件的父類別 (class) 名稱

函數說明
string get_parent_class([mixed $object])$object 為物件。


參數 (parameter) 為物件變數,須注意回傳的是字串。


舉例如下
<?php
class Apple {}
class Apple2 extends Apple {
    function do_something() {
        echo "I'm " , get_parent_class($this) , "'s son\n";
    }
}

$a = new Apple2();
echo get_parent_class($a) . "\n";
$a->do_something();

/* 《程式語言教學誌》的範例程式
    http://pydoing.blogspot.com/
    檔名:object11php
    功能:示範 PHP 程式 
    作者:張凱慶
    時間:西元 2013 年 2 月 */
?>


執行結果如下



中英文術語對照
函數function
陣列array
參數parameter


您可以繼續參考
類別、物件相關函數


相關目錄
回 PHP 快速導覽
回 PHP 教材
回首頁


參考資料
http://www.php.net/manual/en/function.get-parent-class.php

沒有留言: