Skip to content

Instantly share code, notes, and snippets.

@wowo
Created November 16, 2010 01:52
Show Gist options
  • Save wowo/701303 to your computer and use it in GitHub Desktop.
Save wowo/701303 to your computer and use it in GitHub Desktop.
Accessing private members of the same object type
<?php
class Foo
{
private $_property = "Foo";
public function get()
{
return $this->_property;
}
public function modifyProperty(Foo $other, $value)
{
$other->_property = $value;
}
}
$foo = new Foo();
$bar = new Foo();
printf("bar _property: %s\n",$bar->get()); // prints: bar _property: Foo
$foo->modifyProperty($bar, "Bar");
printf("bar _property: %s\n",$bar->get()); // prints: bar _property: Bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment