PHPackages                             drewlabs/overloadable - 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. drewlabs/overloadable

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

drewlabs/overloadable
=====================

Provides function overloading to PHP language. It's an experimental feature as it may not be optimized for all use-case

v0.3.1(1w ago)062515MITPHPPHP ^7.2|^8.0

Since Apr 4Pushed 2y agoCompare

[ Source](https://github.com/azlabsphp/overloadable)[ Packagist](https://packagist.org/packages/drewlabs/overloadable)[ RSS](/packages/drewlabs-overloadable/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (4)Used By (5)

PHP Overloadable
================

[](#php-overloadable)

PHP Library that provides Object Oriented method overloading to PHP class definition. It uses the power of PHP reflexion API to find and call overloaded methods.

**Note**The implementation is experimental as it might not be fully optimize for every use case, and may cause performance heck to your application when multiple overload method is provided.

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

[](#installation)

The recommended way to include the package into your project is by using PHP composer package manager.

In a composer.json at your project or library root folder add the following:

```
{
    // ...
    "require": {
        "drewlabs/overloadable": "^0.1.0"
    }
    // ...
}
```

Usage
-----

[](#usage)

- Inline method overloading:

```
// ...
use Drewlabs\Overloadable\Overloadable;

class TestClass
{
    use Overloadable;

    public function log(...$args)
    {
        return $this->overload($args, [
            static function (ConsoleLogger $logger) {
                return $logger->log();
            },
            static function (FileLogger $logger, ?string $prefix = null) {
                return $logger->log($prefix ?? 'ERROR024');
            },
        ]);
    }
}
```

- Class method overload

```
// ...
use Drewlabs\Overloadable\Overloadable;

class TestClass
{
    use Overloadable;

    public function log(...$args)
    {
        return $this->overload($args, [
            'log1',
            'log2'
        ]);
    }

    private function log1(ConsoleLogger $logger)
    {
        return $logger->log();
    }

    private function log2(FileLogger $logger, ?string $prefix = null)
    {
        return $logger->log($prefix ?? 'ERROR024');
    }
}
```

After library installation is completed, in order to use the overloadable implementations, include the composer autoload file in your project entry script. The example below assume your project entry script is `index.php` :

```
// index.php
// Load composer autoloaded php scripts using PSR4 implementation
require_once __DIR__ 'vendor/autoload.php';

// Calling the overloaded methods
$object = new TestClass();

$object->log(new FileLogger); // Call the overload that accept an instance of FileLogger as 1st parameter
$object->log(new ConsoleLogger); // Call the overload that accept an instance of ConsoleLogger as 1st parameter

$object->log(new ConsoleLogger, 'ERROR CODE 2308'); // Throws execption as there is no overloaded function that matches
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance54

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity42

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.

###  Release Activity

Cadence

Every ~588 days

Total

3

Last Release

10d ago

PHP version history (2 changes)v0.1.10PHP &gt;=7.3

v0.3.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c4973d500c7f4233d5ceacab51a57208d5fb60b0f95ae60264cf92380d0534?d=identicon)[azandrew-sidoine](/maintainers/azandrew-sidoine)

---

Top Contributors

[![azandrew-sidoine](https://avatars.githubusercontent.com/u/23530515?v=4)](https://github.com/azandrew-sidoine "azandrew-sidoine (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drewlabs-overloadable/health.svg)

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

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.2k](/packages/friendsofphp-php-cs-fixer)[w7corp/easywechat

微信SDK

10.4k834.8k64](/packages/w7corp-easywechat)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2603.2M435](/packages/ssch-typo3-rector)[phootwork/lang

Missing PHP language constructs

1228.2M8](/packages/phootwork-lang)

PHPackages © 2026

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