Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > fedef0ce54a3761fc1862157672b700c > files > 3744

php-manual-ar-5.1.6-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>::</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="Constructors"
HREF="language.oop.constructor.html"><LINK
REL="NEXT"
TITLE="parent"
HREF="keyword.parent.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="language.oop.constructor.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="keyword.parent.html"
ACCESSKEY="N"
>Volgende</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="keyword.paamayim-nekudotayim"
><VAR
CLASS="literal"
>::</VAR
></A
></H1
><DIV
CLASS="caution"
><P
></P
><TABLE
CLASS="caution"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Let op</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;     The following is valid for PHP 4 and later only.
    </P
></TD
></TR
></TABLE
></DIV
><P
>&#13;    Sometimes it is useful to refer to functions and variables
    in base classes or to refer to functions in classes that
    have not yet any instances. The :: operator is being used
    for this.
   </P
><DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN4789"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">class </font><font color="#0000BB">A </font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">example</font><font color="#007700">() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"I am the original function A::example().&lt;br /&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />class </font><font color="#0000BB">B </font><font color="#007700">extends </font><font color="#0000BB">A </font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">example</font><font color="#007700">() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"I am the redefined function B::example().&lt;br /&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">A</font><font color="#007700">::</font><font color="#0000BB">example</font><font color="#007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></font><font color="#FF8000">// there is no object of class A.<br />// this will print<br />//&nbsp;&nbsp;&nbsp;I am the original function A::example().&lt;br /&gt;<br /></font><font color="#0000BB">A</font><font color="#007700">::</font><font color="#0000BB">example</font><font color="#007700">();<br /><br /></font><font color="#FF8000">// create an object of class B.<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 print <br />//&nbsp;&nbsp;&nbsp;I am the redefined function B::example().&lt;br /&gt;<br />//&nbsp;&nbsp;&nbsp;I am the original function A::example().&lt;br /&gt;<br /></font><font color="#0000BB">$b</font><font color="#007700">-&gt;</font><font color="#0000BB">example</font><font color="#007700">();<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
></P
></DIV
><P
>&#13;    The above example calls the function example() in
    class A, but there is no object of class A, so that
    we cannot write $a-&#62;example() or similar. Instead we
    call example() as a 'class function', that is, as a
    function of the class itself, not any object of that
    class.
   </P
><P
>&#13;    There are class functions, but there are no class variables.
    In fact, there is no object at all at the time of the call.
    Thus, a class function may not use any object variables (but
    it can use local and global variables), and it may no use
    <VAR
CLASS="varname"
>$this</VAR
> at all.
   </P
><P
>&#13;    In the above example, class B redefines the function example(). 
    The original definition in class A is shadowed
    and no longer available, unless you are referring specifically
    to the implementation of example() in class A using the 
    ::-operator. Write A::example() to do this (in fact, you
    should be writing parent::example(), as shown in the next
    section).
   </P
><P
>&#13;    In this context, there is a current object and it may have object
    variables. Thus, when used from WITHIN an object function, you may use
    <VAR
CLASS="varname"
>$this</VAR
> and object variables.
   </P
></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="language.oop.constructor.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="keyword.parent.html"
ACCESSKEY="N"
>Volgende</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><VAR
CLASS="literal"
>Constructors</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"
><VAR
CLASS="literal"
>parent</VAR
></TD
></TR
></TABLE
></DIV
></BODY
></HTML
>