PHPackages                             rikudou/friend-classes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rikudou/friend-classes

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

rikudou/friend-classes
======================

Allows other classes to access your class private methods/properties

v2.0.0(4y ago)423MITPHPPHP ^8.0

Since Mar 26Pushed 4y agoCompare

[ Source](https://github.com/RikudouSage/PhpFriendClasses)[ Packagist](https://packagist.org/packages/rikudou/friend-classes)[ RSS](/packages/rikudou-friend-classes/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (5)Versions (10)Used By (0)

Friend classes in PHP
=====================

[](#friend-classes-in-php)

Inspired by the concept of friend classes in C++ where you can specify classes that have access to otherwise unaccessible properties.

Example from C++ world:

```
class ClassWithPrivateProperty {
private:
    int myPrivateProperty = 0;

    friend class MyOtherClass; // here we declare MyOtherClass as a friend
}

class MyOtherClass {
public:
    void someMethod() {
        ClassWithPrivateProperty privateObject;
        auto result = privateObject.myPrivateProperty; // allowed because MyOtherClass is declared as a friend of ClassWithPrivateProperty
    }
}
```

Installation
------------

[](#installation)

`composer require rikudou/friend-classes`

That's it, the package is now automatically enabled and works out of the box.

Usage
-----

[](#usage)

After installing this package you can use similar concept in PHP:

```
