=========================================================================
copycode- [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]
|
copycode- [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]
|