class_exists() 与get_class_methods()函数使用实例

| |
| August 27, 2008 11:57 | root | Via 本站原创
[blockquote]<html>
<head>
<title>class_exists()函数使用实例</title>
</head>
<body>
<?
class Window        //首先定义一个类
{
var $state;      //窗户的状态
function close_window()    //关窗户方法
{
  $this->state="close";    //窗户的状态为关
}
function open_window()    //开窗户方法
{
  $this->state="open";    //窗户的状态为开
}
}
class Who_Window extends Window  //创建子类
{
var $owner;
function close_window()    //方法继承
{
  $this->state="close";
  $this->owner="Jack";
}
}
function f_e($string)      //创建一个基于class_exists()的自定义函数
{
if(class_exists($string))    //如果类名存在
{
  echo "名为".$string."的类已经存在!"; //打印相应信息
}
else        //如果类不存在
{
  echo "名为".$string."的类并不存在!"; //打印相应信息
}
}
f_e("Window");        //调用函数
echo "<p>";
f_e("Who_Window");      //调用函数
echo "<p>";
f_e("temp_class");      //调用函数
echo "<p>";
?>
</body>
</html>[/blockquote]


Copy code
[blockquote]<html>
<head>
<title>get_class_methods()函数使用实例</title>
</head>
<body>
<?
class Window                                //首先定义一个类
{
    var $state;                            //窗户的状态
    function close_window()                    //关窗户方法
    {
        $this->state="close";                    //窗户的状态为关
    }
    function open_window()                    //开窗户方法
    {
        $this->state="open";                    //窗户的状态为开
    }
}
$temp=get_class_methods("Window");
echo "类Window中的方法有以下几个:";
echo "<p>";
for($i=0;$i<count($temp);$i++)
{
    echo $temp[$i].",";
}
?>
</body>
</html>[/blockquote]
WEB相关 | 评论(0) | 引用(0) | 阅读(64)
发表评论
 网址
 电邮
  密码 游客无需密码
 昵称  *  [注册]
               

 
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我