Fix #73593: constant visibility needs to be documented

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@341146 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christoph Michael Becker 2016-11-25 23:09:57 +00:00
parent a66ee8dc56
commit 7de45151c2

View file

@ -3,7 +3,7 @@
<sect1 xml:id="language.oop5.visibility" xmlns="http://docbook.org/ns/docbook">
<title>Visibility</title>
<para>
The visibility of a property or method can be defined by prefixing
The visibility of a property, a method or (as of PHP 7.1.0) a constant can be defined by prefixing
the declaration with the keywords <emphasis>public</emphasis>,
<emphasis>protected</emphasis> or
<emphasis>private</emphasis>. Class members declared public can be
@ -189,6 +189,72 @@ $myFoo->test(); // Bar::testPrivate
</para>
</sect2>
<sect2 xml:id="language.oop5.visiblity-constants">
<title>Constant Visibility</title>
<para>
As of PHP 7.1.0, class constants may be defined as public, private, or
protected. Constants declared without any explicit visibility
keyword are defined as public.
</para>
<para>
<example>
<title>Constant Declaration as of PHP 7.1.0</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Define MyClass
*/
class MyClass
{
// Declare a public constant
public const MY_PUBLIC = 'public';
// Declare a protected constant
protected const MY_PROTECTED = 'protected';
// Declare a private constant
private const MY_PRIVATE = 'private';
public function foo()
{
echo self::MY_PUBLIC;
echo self::MY_PROTECTED;
echo self::MY_PRIVATE;
}
}
$myclass = new MyClass();
MyClass::MY_PUBLIC; // Works
MyClass::MY_PROTECTED; // Fatal Error
MyClass::MY_PRIVATE; // Fatal Error
$myclass->foo(); // Public, Protected and Private work
/**
* Define MyClass2
*/
class MyClass2 extends MyClass
{
// This is public
function foo2()
{
echo self::MY_PUBLIC;
echo self::MY_PROTECTED;
echo self::MY_PRIVATE; // Fatal Error
}
}
$myclass2 = new MyClass2;
echo MyClass2::MY_PUBLIC; // Works
$myclass2->foo2(); // Public and Protected work, not Private
?>
]]>
</programlisting>
</example>
</para>
</sect2>
<sect2 xml:id="language.oop5.visibility-other-objects">
<title>Visibility from other objects</title>
<para>