PHPackages                             ricardofbarros/inheritance - 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. ricardofbarros/inheritance

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ricardofbarros/inheritance
==========================

Easy Multiple Inheritance for Classes in PHP

217PHP

Since Jun 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/ricardofbarros/inheritance)[ Packagist](https://packagist.org/packages/ricardofbarros/inheritance)[ RSS](/packages/ricardofbarros-inheritance/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Inheritance
===========

[](#inheritance)

Make multiple inheritances in PHP effortlessly, without alot of fuss and some potential headaches. **It's easy as pie, trust me!**

How does this work?
-------------------

[](#how-does-this-work)

Well it's simple, when you extend 'Inheritance' to your main class (child), you will gain a new method '\_\_inherit', this method will accept an array with objects or the name of your classes, see To construct or not to construct for further understanding, next it will store all non-static public and protected methods and properties using Reflection.

For example, when you call a method it will trigger 'Inheritance' magic method '\_\_call', and if this method exists in any class inherited, it will invoke this method.

Inheritances uses the following magic methods '\_\_call', '\_\_set', '\_\_get'

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

[](#installation)

### Composer Install

[](#composer-install)

Just follow these simple steps to install Inheritance in your project:

1. Get [Composer](http://getcomposer.org)
2. Run this command to install Inheritance in your project dir

```
composer require ricardofbarros/inheritance:dev-master
```

3. Start inheriting stuff right away

```
class ClassA extends \Inheritance {

...

}
```

### Manual Install

[](#manual-install)

Download and extract the Inheritance package into your project directory and require it and register Inheritance autoloader in your application’s bootstrap file.

```
require "path/to/inheritance/src/Inheritance.php"

Inheritance::registerAutoloader();
```

Basic Usage
-----------

[](#basic-usage)

```
## ClassA.php
class ClassA extends \Inheritance {

    public function __construct() {
        parent::__inherit(array(
            new ClassB(),
            new ClassC()
         ));
    }

    public function test() {
       return parent::hello().' '.parent::world();
    }
}

## ClassB.php
class ClassB  {
    protected function hello() {
        return 'Hello';
    }
}

## ClassC.php
class ClassC {
    protected function world() {
        return 'World!';
    }
}

## somefile.php
$class = new ClassA();

// Output : Hello World!
echo $class->test();
```

> **NOTE:** For some more usage examples, see files in `examples` dir

To construct or not to construct?
---------------------------------

[](#to-construct-or-not-to-construct)

You can decide if you want to construct a class or just bypass the '\_\_constructor', it's very simple to do that just see the example bellow.

```
class ClassA extends \Inheritance {

    public function __construct() {
        parent::__inherit(array(
            'ClassB', // This will instance the class bypassing a potential existence of a constructor
            new ClassC() // This will call __construct() as expected
         ));
    }

    public function test() {
       return parent::hello().' '.parent::world();
    }
}
```

Features
--------

[](#features)

- Access to protected and public methods
- Access to protected and public properties
- Throw exceptions for the use of protected properties and methods in an invalid scope
- Decide which classes inherited you want to construct or instantiate without constructing

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/acd1410caf10a72fff16bdd328a30f505347d3bb6353b4af00f8a7b3507494cf?d=identicon)[ricardofbarros](/maintainers/ricardofbarros)

---

Top Contributors

[![ricardofbarros](https://avatars.githubusercontent.com/u/6867996?v=4)](https://github.com/ricardofbarros "ricardofbarros (22 commits)")

### Embed Badge

![Health badge](/badges/ricardofbarros-inheritance/health.svg)

```
[![Health](https://phpackages.com/badges/ricardofbarros-inheritance/health.svg)](https://phpackages.com/packages/ricardofbarros-inheritance)
```

###  Alternatives

[symfony/polyfill-uuid

Symfony polyfill for uuid functions

688335.4M63](/packages/symfony-polyfill-uuid)[spatie/error-solutions

This is my package error-solutions

6853.2M11](/packages/spatie-error-solutions)[phpflo/phpflo

Flow-based programming for PHP

2173.3k4](/packages/phpflo-phpflo)[eftec/autoloadone

AutoloadOne is a program that generates an autoload class for PHP.

403.4k](/packages/eftec-autoloadone)[ys-tools/default-theme-configuration-bundle

OroCommerce Default Theme Configuration Bundle

124.2k](/packages/ys-tools-default-theme-configuration-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
