Created
November 16, 2010 01:52
-
-
Save wowo/701303 to your computer and use it in GitHub Desktop.
Accessing private members of the same object type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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