php-doc-en/language/oop5/visibility.xml
Dave Barr 5aa855b67e - Typo.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@166223 c90b9560-bf6c-de11-be94-00142212c4b1
2004-08-13 01:00:48 +00:00

111 lines
3 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<sect1 id="language.oop5.visibility">
<title>Visibility</title>
<para>
The visibility of a property or method can be defined by prefixing the
declaration with the keywords: public, protected or private. Public
declared items can be accessed everywhere. Protected limits access to
inherited classes (and to the class that defines the item). Private limits
visibility only to the class that defines the item.
</para>
<sect2 id="language.oop5.visiblity-members">
<title>Members Visibility</title>
<para>
Class members must be defined with public, private, or protected.
</para>
<example>
<title>Member declaration</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
public $public = "MyClass::public!\n";
protected $protected = "MyClass::Protected!\n";
protected $protected2 = "MyClass::Protected2!\n";
private $private = "MyClass::private!\n";
function printHello() {
print "MyClass::printHello() " . $this->private;
print "MyClass::printHello() " . $this->protected;
print "MyClass::printHello() " . $this->protected2;
}
}
class MyClass2 extends MyClass {
protected $protected = "MyClass2::protected!\n";
function printHello() {
MyClass::printHello();
print "MyClass2::printHello() " . $this->public;
print "MyClass2::printHello() " . $this->protected;
print "MyClass2::printHello() " . $this->protected2;
/* Will result in a Fatal Error: */
//print "MyClass2::printHello() " . $this->private; /* Fatal Error */
}
}
$obj = new MyClass();
print "Main:: " . $obj->public;
//print $obj->private; /* Fatal Error */
//print $obj->protected; /* Fatal Error */
//print $obj->protected2; /* Fatal Error */
$obj->printHello(); /* Should print */
$obj2 = new MyClass2();
print "Main:: " . $obj2->private; /* Undefined */
//print $obj2->protected; /* Fatal Error */
//print $obj2->protected2; /* Fatal Error */
$obj2->printHello();
?>
]]>
</programlisting>
</example>
<note>
<simpara>
The use PHP 4 use of declaring a variable with the keyword 'var' is
no longer valid for PHP 5 objects. For compatibility a variable declared
in php will be assumed with public visibility, and a
<constant>E_STRICT</constant> warning will be issued.
</simpara>
</note>
</sect2>
<sect2 id="language.oop5.visiblity-methods">
<title>Method Visibility</title>
<para>
.
</para>
</sect2>
</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
-->