Skip to content

Instantly share code, notes, and snippets.

Created May 17, 2011 09:11
What would you like to do?
Accessing private members of the same object type
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';
// We can also call the private method:
$test = new Test('test');
$test->baz(new Test('other'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment