PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<::序列化对象 - 会话中的对象>
Last updated: Sat, 20 Oct 2007

parent

你可能会发现自己写的代码访问了基类的变量和函数。如果派生类非常精炼或者基类非常专业化的时候尤其是这样。

不要用代码中基类文字上的名字,应该用特殊的名字 parent,它指的就是派生类在 extends 声明中所指的基类的名字。这样做可以避免在多个地方使用基类的名字。 如果继承树在实现的过程中要修改,只要简单地修改类中 extends 声明的部分。

<?php
class A
{
   function
example()
   {
       echo
"I am A::example() and provide basic functionality.<br>\n";
   }
}

class
B extends A
{
   function
example()
   {
       echo
"I am B::example() and provide additional functionality.<br>\n";
      
parent::example();
   }
}

$b = new B;

// 这将调用 B::example(),而它会去调用 A::example()。
$b->example();
?>




<::序列化对象 - 会话中的对象>
 Last updated: Sat, 20 Oct 2007
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST