svn: /phpdoc/en/trunk/language/oop5/ visibility.xml
| From: | Daniel Egeberg | Date: | Fri, 11 Jun 2010 08:55:34 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/oop5/ visibility.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-6806@lists.php.net to get a copy of this message | ||
degeberg Fri, 11 Jun 2010 08:55:34 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=300372
Log:
Explained that it is possible accessing private and protected members of other instances of the same
object type.
Changed paths:
U phpdoc/en/trunk/language/oop5/visibility.xml
Modified: phpdoc/en/trunk/language/oop5/visibility.xml
===================================================================
--- phpdoc/en/trunk/language/oop5/visibility.xml 2010-06-11 08:53:31 UTC (rev 300371)
+++ phpdoc/en/trunk/language/oop5/visibility.xml 2010-06-11 08:55:34 UTC (rev 300372)
@@ -12,6 +12,7 @@
classes. Members declared as private may only be accessed by the
class that defines the member.
</para>
+
<sect2 xml:id="language.oop5.visibility-members">
<title>Property Visibility</title>
<para>
@@ -86,6 +87,7 @@
</simpara>
</note>
</sect2>
+
<sect2 xml:id="language.oop5.visiblity-methods">
<title>Method Visibility</title>
<para>
@@ -186,6 +188,60 @@
</example>
</para>
</sect2>
+
+ <sect2 xml:id="language.oop5.visibility-other-objects">
+ <title>Visibility from other objects</title>
+ <para>
+ Objects of the same type will have access to each others private and
+ protected members even though they are not the same instances. This is
+ because the implementation specific details are already known when inside
+ those objects.
+ </para>
+ <example>
+ <title>Accessing private members of the same object type</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+class Test
+{
+ private $foo;
+
+ public function __construct($foo)
+ {
+ $this->foo = $foo;
+ }
+
+ private function bar()
+ {
+ echo 'Accessed the private method.';
+ }
+
+ public function baz(Test $other)
+ {
+ // We can change the private property:
+ $other->foo = 'hello';
+ var_dump($other->foo);
+
+ // We can also call the private method:
+ $other->bar();
+ }
+}
+
+$test = new Test('test');
+
+$test->baz(new Test('other'));
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+string(5) "hello"
+Accessed the private method.
+]]>
+ </screen>
+ </example>
+ </sect2>
</sect1>
<!-- Keep this comment at the end of the file