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