mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Document that interfaces can have constants
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@264720 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
e430cd9972
commit
c58e78bda6
2 changed files with 40 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.16 $ -->
|
||||
<!-- $Revision: 1.17 $ -->
|
||||
<sect1 xml:id="language.oop5.constants" xmlns="http://docbook.org/ns/docbook">
|
||||
<title>Class Constants</title>
|
||||
<para>
|
||||
|
@ -11,13 +11,16 @@
|
|||
The value must be a constant expression, not (for example) a variable, a
|
||||
class member, result of a mathematical operation or a function call.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Its also possible for interfaces to have <literal>constants</literal>. Look at
|
||||
the <link linkend="language.oop5.interfaces">interface documentation</link> for
|
||||
examples.
|
||||
</para>
|
||||
<para>
|
||||
As of PHP 5.3.0, it's possible to reference the class using a variable.
|
||||
The variable's value can not be a keyword (e.g. <literal>self</literal>,
|
||||
<literal>parent</literal> and <literal>static</literal>).
|
||||
</para>
|
||||
|
||||
<example>
|
||||
<title>Defining and using a constant</title>
|
||||
<programlisting role="php">
|
||||
|
@ -64,13 +67,11 @@ EOT;
|
|||
Unlike heredocs, nowdocs can be used in any static data context.
|
||||
</para>
|
||||
</example>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
Nowdoc support was added in PHP 5.3.0.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
</sect1>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.13 $ -->
|
||||
<!-- $Revision: 1.14 $ -->
|
||||
<sect1 xml:id="language.oop5.interfaces" xmlns="http://docbook.org/ns/docbook">
|
||||
<title>Object Interfaces</title>
|
||||
<para>
|
||||
|
@ -37,6 +37,14 @@
|
|||
</para>
|
||||
</note>
|
||||
</sect2>
|
||||
<sect2 xml:id="language.oop5.interfaces.constants">
|
||||
<title><literal>Constants</literal></title>
|
||||
<para>
|
||||
Its possible for interfaces to have constants. Interface constants works exactly
|
||||
like <link linkend="language.oop5.constants">class constants</link>. They cannot
|
||||
be overridden by a class/interface that inherits it.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 xml:id="language.oop5.interfaces.examples">
|
||||
&reftitle.examples;
|
||||
<example xml:id="language.oop5.interfaces.examples.ex1">
|
||||
|
@ -157,17 +165,40 @@ class d implements c
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
public function bar()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function baz()
|
||||
{
|
||||
}
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example xml:id="language.oop5.interfaces.examples.ex4">
|
||||
<title>Interfaces with constants</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
interface a
|
||||
{
|
||||
const b = 'Interface constant';
|
||||
}
|
||||
|
||||
// Prints: Interface constant
|
||||
echo a::b;
|
||||
|
||||
|
||||
// This will however not work because its not allowed to
|
||||
// override constants. This is the same concept as with
|
||||
// class constants
|
||||
class b implements a
|
||||
{
|
||||
const b = 'Class constant';
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
|
Loading…
Reference in a new issue