请输入您要查询的百科知识:

 

词条 get_class
释义

get_cla

(PHP 4, PHP 5)

get_class -- 返回对象的类名

说明

string get_class ( [object obj] )

返回对象实例 obj 所属类的名字。如果 obj 不是一个对象则返回 FALSE

注: 在 PHP 扩展库中定义的类返回其原始定义的名字。在 PHP 4 中 get_class() 返回用户定义的类名的小写形式,但是在 PHP 5 中将返回类名定义时的名字,如同扩展库中的类名一样。

注: 自 PHP 5 起,如果在对象的方法中调用则 obj 为可选项。

使用 get_class()

<?php

class foo {

function foo()

{

// implements some logic

}

function name()

{

echo "My name is " , get_class($this) , "\";

}

}

// create an object

$bar = new foo();

// external call

echo "Its name is " , get_class($bar) , "\";

// internal call

$bar->name();

?>

输出:

Its name is foo
My name is foo

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/20 10:10:15