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

php私有成员private的程序题目

时间:2014-10-13 20:31:37      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   on   cti   

class base
{
  private $member;

  function __construct()
  {
      echo __METHOD__ . "(begin)\n";
    $this->member = ‘base::member‘;
    $this->test();
      echo __METHOD__ . "(end)\n";
  }

  function test()
  {
      echo __METHOD__ . "\n";
    print_r($this);
  }
}

class derived extends base
{
  public $member = ‘derived::member (default)‘;

  function __construct()
  {
      echo __METHOD__ . "(begin)\n";
      parent::__construct();
      parent::test();
    
      $this->test();
    $this->member = ‘derived::member‘;
      echo __METHOD__ . "(end)\n";
  }

  function test()
  {
      parent::test();
      echo __METHOD__ . "\n";
    print_r($this);
  }
}

$t = new derived();
$t->test();
unset($t);

打印结果为:

 1 derived::__construct(begin)
 2 base::__construct(begin)
 3 base::test
 4 derived Object
 5 (
 6     [member] => derived::member (default)
 7     [member:base:private] => base::member
 8 )
 9 derived::test
10 derived Object
11 (
12     [member] => derived::member (default)
13     [member:base:private] => base::member
14 )
15 base::__construct(end)
16 base::test
17 derived Object
18 (
19     [member] => derived::member (default)
20     [member:base:private] => base::member
21 )
22 base::test
23 derived Object
24 (
25     [member] => derived::member (default)
26     [member:base:private] => base::member
27 )
28 derived::test
29 derived Object
30 (
31     [member] => derived::member (default)
32     [member:base:private] => base::member
33 )
34 derived::__construct(end)
35 base::test
36 derived Object
37 (
38     [member] => derived::member
39     [member:base:private] => base::member
40 )
41 derived::test
42 derived Object
43 (
44     [member] => derived::member
45     [member:base:private] => base::member
46 )
47 Done

 

php私有成员private的程序题目

标签:style   blog   color   io   ar   sp   div   on   cti   

原文地址:http://www.cnblogs.com/hylaz/p/4022776.html

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