PHPackages                             typhoon/overloading - 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. typhoon/overloading

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

typhoon/overloading
===================

The missing method overloading feature for PHP.

0.1.1(2y ago)459MITPHPPHP ^8.1

Since Nov 24Pushed 2y ago2 watchersCompare

[ Source](https://github.com/typhoon-php/overloading)[ Packagist](https://packagist.org/packages/typhoon/overloading)[ RSS](/packages/typhoon-overloading/feed)WikiDiscussions 0.1.x Synced today

READMEChangelog (2)Dependencies (13)Versions (3)Used By (0)

Typhoon Overloading
===================

[](#typhoon-overloading)

The missing method overloading feature for PHP.

[![PHP Version Require](https://camo.githubusercontent.com/dd3f48d94c3a23f877504284680496ae57df36942251dc5e9c22b5805eb10ed8/687474703a2f2f706f7365722e707567782e6f72672f747970686f6f6e2f6f7665726c6f6164696e672f726571756972652f706870)](https://packagist.org/packages/typhoon/overloading)[![Latest Stable Version](https://camo.githubusercontent.com/498346367b3ab409076317f3d831562d7b089fae03063681e6969c695f047e68/68747470733a2f2f706f7365722e707567782e6f72672f747970686f6f6e2f6f7665726c6f6164696e672f762f737461626c652e706e67)](https://packagist.org/packages/typhoon/overloading)[![Total Downloads](https://camo.githubusercontent.com/8ffdaf053857315f44470a7c92d297501a5c04e2e2b368e79aaf66edff3634af/68747470733a2f2f706f7365722e707567782e6f72672f747970686f6f6e2f6f7665726c6f6164696e672f646f776e6c6f6164732e706e67)](https://packagist.org/packages/typhoon/overloading)[![psalm-level](https://camo.githubusercontent.com/ef44ebc917a91b270826905d43481685009d0cbcc226af499888f1046da2726d/68747470733a2f2f73686570686572642e6465762f6769746875622f747970686f6f6e2d7068702f6f7665726c6f6164696e672f6c6576656c2e737667)](https://shepherd.dev/github/typhoon-php/overloading)[![type-coverage](https://camo.githubusercontent.com/9b566c2c14e7f22a8f151b7b14a28a27bea7c42d623475d68bd8fa66308d471b/68747470733a2f2f73686570686572642e6465762f6769746875622f747970686f6f6e2d7068702f6f7665726c6f6164696e672f636f7665726167652e737667)](https://shepherd.dev/github/typhoon-php/overloading)[![Code Coverage](https://camo.githubusercontent.com/f124bd2958bcbac8caf6b01287247922b70393ed580604b9e05aedcd117be50b/68747470733a2f2f636f6465636f762e696f2f67682f747970686f6f6e2d7068702f6f7665726c6f6164696e672f6272616e63682f302e312e782f67726170682f62616467652e737667)](https://codecov.io/gh/typhoon-php/overloading/tree/0.1.x)[![Mutation testing badge](https://camo.githubusercontent.com/a51e08bf08b7ccb68ef2f3f9a8382ce93a533cd8076faee86f756a2a91102f29/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246747970686f6f6e2d7068702532466f7665726c6f6164696e67253246302e312e78)](https://dashboard.stryker-mutator.io/reports/github.com/typhoon-php/overloading/0.1.x)

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

[](#installation)

`composer require typhoon/overloading`

Usage
-----

[](#usage)

To mark methods `handleInt` and `handleString` as overloading method `handle`, add `#[Overload('handle')]` attribute to `handleInt` and `handleString` and call `Overload::call()` from `handle`. You do not need to pass arguments to `Overload::call()`, this happens automagically. However, return `Overload::call()` explicitly if you need to. After this you will be able to call `handle` with any arguments and reach overloading methods when their signature matches.

```
use Typhoon\Overloading\Overload;

final class WhateverHandler
{
    public function handle(mixed ...$args): string
    {
        return Overload::call();
    }

    #[Overload('handle')]
    public function handleInt(int $int): string
    {
        return __METHOD__;
    }

    #[Overload('handle')]
    public function handleString(string $string): string
    {
        return __METHOD__;
    }

    #[Overload('handle')]
    public function handleStdClass(\stdClass $object): string
    {
        return __METHOD__;
    }

    #[Overload('handle')]
    public function handleNamedOptionalArguments(int $int = 0, float $float = M_E): string
    {
        return __METHOD__;
    }
}

$handler = new WhateverHandler();

// WhateverHandler::handleInt
var_dump($handler->handle(300));

// WhateverHandler::handleString
var_dump($handler->handle('Hello world!'));

// WhateverHandler::handleStdClass
var_dump($handler->handle(new \stdClass()));

// WhateverHandler::handleNamedOptionalArguments
var_dump($handler->handle(float: 1.5));

// WhateverHandler::handleNamedOptionalArguments
var_dump($handler->handle());

// No matching overloading methods for WhateverHandler::handle(string, bool).
var_dump($handler->handle('Hey!', true));
```

What about speed?
-----------------

[](#what-about-speed)

Well, using overloading is obviously slower, than calling a method directly, but not awfully slower. Here's a simple benchmark for the `WhateverHandler`:

```
// warm up
$handler->handle();

\DragonCode\Benchmark\Benchmark::start()
    ->withoutData()
    ->round(2)
    ->compare([
        'direct call' => static fn (): string => $handler->handleNamedOptionalArguments(),
        'overloaded call' => static fn (): string => $handler->handle(),
    ]);
```

```
 ------- ---------------- -------------------
  #       direct call      overloaded call
 ------- ---------------- -------------------
  min     0 ms - 0 bytes   0 ms - 0 bytes
  max     0 ms - 0 bytes   0.02 ms - 0 bytes
  avg     0 ms - 0 bytes   0 ms - 0 bytes
  total   0.95 ms          1.16 ms
 ------- ---------------- -------------------
  Order   - 1 -            - 2 -
 ------- ---------------- -------------------
```

It's important to understand that memoization plays a very important role here. CLI workers and applications, served via Roadrunner, for instance, will benefit from this. For PHP-FPM you can enable file cache suitable for OPcaching via `Overload::useFileCache('/path/to/cache');`.

TODO
----

[](#todo)

- Finish tests.
- Explain caching in README.
- Optimize generated code.
- Inherit attributes from upstream method declarations.
- Allow to warm up classes.
- Psalm plugin.
- PHPStan plugin.
- Support static analysis types.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

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 ~2 days

Total

3

Last Release

948d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2552865?v=4)[Valentin Udaltsov](/maintainers/vudaltsov)[@vudaltsov](https://github.com/vudaltsov)

---

Top Contributors

[![vudaltsov](https://avatars.githubusercontent.com/u/2552865?v=4)](https://github.com/vudaltsov "vudaltsov (8 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/typhoon-overloading/health.svg)

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

###  Alternatives

[pluginscart/dynamodb-php

Access AWS DynamoDB through simpler interface in PHP.

1114.7k](/packages/pluginscart-dynamodb-php)

PHPackages © 2026

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