Last active
August 29, 2015 14:06
-
-
Save bcremer/47bdb7bf51d6127bc364 to your computer and use it in GitHub Desktop.
PHP Class Visibility
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 php_class_visibility.php | |
private method called. | |
private method called. |
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 SomeClass | |
{ | |
private function myPrivate() | |
{ | |
echo "private method called.\n"; | |
} | |
public static function createMe() | |
{ | |
$object = new static(); | |
$object->myPrivate(); // call private method | |
return $object; | |
} | |
public function callOthersPrivate(SomeClass $object) | |
{ | |
$object->myPrivate(); | |
} | |
} | |
$object = SomeClass::createMe(); | |
$anotherObject = new SomeClass(); | |
$object->callOthersPrivate($anotherObject); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment