首页 > 代码库 > php私有成员private的程序题目

php私有成员private的程序题目

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::test10 derived Object11 (12     [member] => derived::member (default)13     [member:base:private] => base::member14 )15 base::__construct(end)16 base::test17 derived Object18 (19     [member] => derived::member (default)20     [member:base:private] => base::member21 )22 base::test23 derived Object24 (25     [member] => derived::member (default)26     [member:base:private] => base::member27 )28 derived::test29 derived Object30 (31     [member] => derived::member (default)32     [member:base:private] => base::member33 )34 derived::__construct(end)35 base::test36 derived Object37 (38     [member] => derived::member39     [member:base:private] => base::member40 )41 derived::test42 derived Object43 (44     [member] => derived::member45     [member:base:private] => base::member46 )47 Done

 

php私有成员private的程序题目