In this tutorial we will see the visibility of the properties/methods of Objects of the same class, wherein same type of objects can access each other's protected/private members and also both the instances are not same.
Let us create a file test.php
public function __construct($xyz)
private function bar()
echo 'This is a private method of any object that belongs to the class testObject.';
public function baz($any)
//Here we are changing the value of private property of an object:
$any->abc='Hello World ';
//Another object $any calls the private function of class testObject
$test = new testObject('xyz123'); //parameter passed to the constructor of class testObject
//Here an object "$test" calls the public function "baz" wherein we call the private function of another object i.e. "$any" of same class.
string(12) "Hello World "
This is a private method of any object that belongs to the class testObject.