Forked from mathiasverraes/private_properties1.php
Last active
August 29, 2015 14:11
-
-
Save muhamed-didovic/8b0e9f208ab68cd04692 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 $private; | |
| public function __construct($value) | |
| { | |
| $this->private = $value; | |
| } | |
| public function getOther(Foo $object) | |
| { | |
| return $object->private; | |
| } | |
| } | |
| $foo1 = new Foo('foo1'); | |
| $foo2 = new Foo('foo2'); | |
| echo $foo1->getOther($foo2); // outputs 'foo2' |
This file contains hidden or 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 | |
| { | |
| // ... | |
| public function equals(Foo $other) | |
| { | |
| return $this->private === $other->private; | |
| } | |
| } | |
| // ... | |
| echo $foo1->equals($foo2) ? 'Equal' : 'Different'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment