Visibility from other objects

Source: Internet
Author: User

Php.net

<?PHPclassTest {Private $foo;  Public function__construct ($foo)     {         $this->foo=$foo; }      Public functionBar () {Echo' Accessed the private method. '; }      Public functionBaz (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=NewTest (' Test ');$test->baz (NewTest (' other '));

D:\WAMP64\WWW\W\W.PHP:20:string ' Hello ' (length=5Private method.

Objects of the same type would have access to each others private and protected members even though they is not the SAM E instances. This is because the implementation specific details be already known when inside those objects.

Objects of the same class can access each other's private and protected members, even if they are not the same instance. This is due to the fact that the specifics of the implementation within these objects are known.

Visibility from other objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.