The Constsnts documentation for oop5

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@163601 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Curt Zirzow 2004-07-19 04:52:41 +00:00
parent f8f96acab7
commit 85522e21df

View file

@ -1,11 +1,38 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<!-- $Revision: 1.2 $ -->
<sect1 id="language.oop5.constants">
<title>Object Constants</title>
<para>
.
It is possible to define constant values on a per-class basis remaining
the same and unchangeable. Constant's differ from normal variables
in that you dont use the <varname>$</varname> symbol to declare or use
them. Like <xref linkend="language.oop5.static"/> members, constant
values can not be accessed with a variable that is an instance of the
object.
</para>
<example>
<title>Defining and using a constant</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
const constant = 'constant value';
function showConstant() {
echo self::constant . "\n";
}
}
echo MyClass::constant . "\n";
$class = new MyClass();
$class->showConstant();
/* echo $class::constant; is not allowed */
?>
]]>
</programlisting>
</example>
</sect1>