Php-function-get-class

提供:Dev Guides
2020年6月23日 (火) 02:46時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

PHP-関数get_class()

構文

get_class ( $object );

定義と使い方

この関数は、指定されたオブジェクトのクラスの名前を取得します。

パラメーター

Sr.No Parameter & Description
1

object(Required)

テストされたオブジェクト。

戻り値

オブジェクトがインスタンスであるクラスの名前を返します。 オブジェクトがオブジェクトでない場合、FALSEを返します。

以下は、この機能の使用法です-

<?php
   class f1 {
      function f1() {
        //implements some logic
      }

      function name() {
         echo "My name is " , get_class($this) , "\n";
      }
   }

  //create an object
   $bar = new f1();

  //external call
   echo "Its name is " , get_class($bar) , "\n";

  //internal call
   $bar->name();
?>

それは次の結果を生成します-

Its name is f1
My name is f1