Skip to content

Instantly share code, notes, and snippets.

@bcremer
Last active August 29, 2015 14:06
Show Gist options
  • Save bcremer/47bdb7bf51d6127bc364 to your computer and use it in GitHub Desktop.
Save bcremer/47bdb7bf51d6127bc364 to your computer and use it in GitHub Desktop.
PHP Class Visibility
$ php php_class_visibility.php
private method called.
private method called.
<?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