mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-21 03:18:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@163821 c90b9560-bf6c-de11-be94-00142212c4b1
127 lines
3 KiB
XML
127 lines
3 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.4 $ -->
|
|
<sect1 id="language.oop5.paamayim-nekudotayim">
|
|
<title>::</title>
|
|
|
|
<para>
|
|
The Paamayim Nekudotayim, or in simpler terms, the double colon.
|
|
This token provides a way to access <link
|
|
linkend="language.oop5.static">static</link>, <link
|
|
linkend="language.oop5.constants">constant</link> or overridden members
|
|
or methods of a class.
|
|
</para>
|
|
|
|
<para>
|
|
When referencing these items from outside the class definition, you use
|
|
name of the class.
|
|
</para>
|
|
|
|
<para>
|
|
Paamayim Nekudotayim would, at first, seem a strange choice for a
|
|
double-colon. However, at the time of writing of Zend Engine 0.5
|
|
(which powered PHP3), that is what Andi and Zeev decided to call it.
|
|
It actually does mean double-colon - in Hebrew! As PHP has progressed
|
|
with its development it has just never changed.
|
|
</para>
|
|
|
|
<example>
|
|
<title>:: from outside class definition</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class MyClass {
|
|
const CONST_VALUE = 'A constant value';
|
|
}
|
|
echo MyClass::CONST_VALUE;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<para>
|
|
Two special keywords <varname>self</varname> and <varname>parent</varname>
|
|
are used to access members or methods from inside the class definition.
|
|
</para>
|
|
|
|
<example>
|
|
<title>:: from inside the class definition</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class OtherClass extends MyClass {
|
|
public static $my_static = 'static var';
|
|
|
|
public static function doubleColon() {
|
|
echo parent::CONST_VALUE . "\n";
|
|
echo self::$my_static . "\n";
|
|
}
|
|
}
|
|
|
|
OtherClass::doubleColon();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<para>
|
|
When an extending class overrides the parents definition of a method,
|
|
php will not call the parent's method. It is up to the extending class
|
|
to call the parent method or not, this also applies to <link
|
|
linkend="language.oop5.decon">Constructors and Destructors</link>, <link
|
|
linkend="language.oop5.overloading">Overloading</link> and <link
|
|
linkend="language.oop5.magic">Magic</link> method defintions as well.
|
|
</para>
|
|
|
|
<example>
|
|
<title>Calling a parent's method</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class MyClass {
|
|
|
|
protected function myFunc() {
|
|
echo "MyClass::myFunc()\n";
|
|
}
|
|
}
|
|
|
|
class OtherClass extends MyClass {
|
|
|
|
/* Override parent's definition */
|
|
public function myFunc() {
|
|
|
|
/* But still call the parent function */
|
|
parent::myFunc();
|
|
echo "OtherClass::myFunc()\n";
|
|
}
|
|
}
|
|
|
|
$class = new OtherClass();
|
|
$class->myFunc();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
</sect1>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|