Re: svn: /phpdoc/en/trunk/language/oop5/ visibility.xml
| From: | Richard Quadling | Date: | Fri, 11 Jun 2010 09:16:15 +0000 |
| Subject: | Re: svn: /phpdoc/en/trunk/language/oop5/ visibility.xml | ||
| References: | 1 | Groups: | php.doc.cvs |
| Request: | Send a blank email to doc-cvs+get-6807@lists.php.net to get a copy of this message | ||
On 11 June 2010 09:55, Daniel Egeberg <degeberg@php.net> wrote:
> 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
>
>
> --
> PHP Documentation Commits Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
That "smells" like a bug. Private not being private. Sort of isn't
private anymore. I know that everyone in the company has a bank
account, but I can't get to it just because I know how to read my own.
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling