码迷,mamicode.com
首页 > Web开发 > 详细

php -- 类

时间:2014-05-25 23:18:18      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   c   code   

----- 009-class.php -----

bubuko.com,布布扣
 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="content-type" content="text/html; charset=utf-8">
 5     <title>一个PHP网页</title>
 6 </head>
 7 <body>
 8 <pre>
 9 <?php
10     echo "当前页面是:", __file__, "<br/>";
11     class Monitor
12     {
13         private $name = "显示器";
14         public function iam()
15         {
16             echo "我是", $this->name;
17         }
18     }
19     class A
20     {
21         function foo()
22         {
23             if(isset($this)){
24                 echo ‘$this id defined (‘, get_class($this), ")\n";
25             }
26             else{
27                 echo ‘$this is not defined‘, "\n";
28             }
29         }
30     }
31     class B
32     {
33         function bar()
34         {
35             A::foo();
36         }
37     }
38     echo ‘<h3>$this 变量测试</h3>‘;
39     $a = @new A();
40     @$a->foo();
41     @A::foo();
42     $b = @new B();
43     @$b->bar();
44     @B::bar();
45 ?>
46 </pre>
47 </body>
48 </html>
bubuko.com,布布扣

bubuko.com,布布扣

----- 009-class2.php -----

bubuko.com,布布扣
 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="content-type" content="text/html; charset=utf-8">
 5     <title>一个PHP网页</title>
 6 </head>
 7 <body>
 8 <?php
 9     function __autoload($class_name)
10     {
11         require_once("009-class.php");
12     }
13     echo "当前页面是:", __file__, "<br/>";
14     class CRT extends Monitor
15     {
16         public $name;
17         function CRT()
18         {
19             $this->name = "CRT显示器";
20         }
21         public function iam()
22         {
23             $the = "name";
24             echo "我是", $this->$the, "<br/>";
25             echo "我的祖先是";
26             parent::iam();
27         }
28         function __destruct()
29         {
30             echo("<br>这里是析构函数");
31         }
32     }
33     $crt = new CRT();
34     $crt->iam();
35 ?>
36 </body>
37 </html>
bubuko.com,布布扣

bubuko.com,布布扣

php -- 类,布布扣,bubuko.com

php -- 类

标签:des   style   class   blog   c   code   

原文地址:http://www.cnblogs.com/baijifeilong/p/3750393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!