<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >parent</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Handleiding" HREF="index.html"><LINK REL="UP" TITLE="Classes and Objects (PHP 4)" HREF="language.oop.html"><LINK REL="PREVIOUS" TITLE="::" HREF="keyword.paamayim-nekudotayim.html"><LINK REL="NEXT" TITLE="Serializing objects - objects in sessions" HREF="language.oop.serialization.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Handleiding</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="keyword.paamayim-nekudotayim.html" ACCESSKEY="P" >Terug</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Hoofdstuk 13. Classes and Objects (PHP 4)</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.oop.serialization.html" ACCESSKEY="N" >Volgende</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="keyword.parent" ><VAR CLASS="literal" >parent</VAR ></A ></H1 ><P > You may find yourself writing code that refers to variables and functions in base classes. This is particularly true if your derived class is a refinement or specialisation of code in your base class. </P ><P > Instead of using the literal name of the base class in your code, you should be using the special name <VAR CLASS="literal" >parent</VAR >, which refers to the name of your base class as given in the <VAR CLASS="literal" >extends</VAR > declaration of your class. By doing this, you avoid using the name of your base class in more than one place. Should your inheritance tree change during implementation, the change is easily made by simply changing the <VAR CLASS="literal" >extends</VAR > declaration of your class. </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN4805" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">class </font><font color="#0000BB">A </font><font color="#007700">{<br /> function </font><font color="#0000BB">example</font><font color="#007700">() {<br /> echo </font><font color="#DD0000">"I am A::example() and provide basic functionality.<br />\n"</font><font color="#007700">;<br /> }<br />}<br /><br />class </font><font color="#0000BB">B </font><font color="#007700">extends </font><font color="#0000BB">A </font><font color="#007700">{<br /> function </font><font color="#0000BB">example</font><font color="#007700">() {<br /> echo </font><font color="#DD0000">"I am B::example() and provide additional functionality.<br />\n"</font><font color="#007700">;<br /> </font><font color="#0000BB">parent</font><font color="#007700">::</font><font color="#0000BB">example</font><font color="#007700">();<br /> }<br />}<br /><br /></font><font color="#0000BB">$b </font><font color="#007700">= new </font><font color="#0000BB">B</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// This will call B::example(), which will in turn call A::example().<br /></font><font color="#0000BB">$b</font><font color="#007700">-></font><font color="#0000BB">example</font><font color="#007700">();<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="keyword.paamayim-nekudotayim.html" ACCESSKEY="P" >Terug</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Begin</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="language.oop.serialization.html" ACCESSKEY="N" >Volgende</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><VAR CLASS="literal" >::</VAR ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.oop.html" ACCESSKEY="U" >Omhoog</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Serializing objects - objects in sessions</TD ></TR ></TABLE ></DIV ></BODY ></HTML >