PHPackages                             sevavietl/overloaded-function - 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. sevavietl/overloaded-function

ActiveLibrary

sevavietl/overloaded-function
=============================

Function overloading wrapper for php.

371PHP

Since Mar 9Pushed 7y ago2 watchersCompare

[ Source](https://github.com/Sevavietl/OverloadedFunction)[ Packagist](https://packagist.org/packages/sevavietl/overloaded-function)[ RSS](/packages/sevavietl-overloaded-function/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Overloaded Function
===================

[](#overloaded-function)

[![Build Status](https://camo.githubusercontent.com/4287f072ca3960a6a9cfb6fd139d8687749d3ac5aa6435d699eab93c600525ff/68747470733a2f2f7472617669732d63692e636f6d2f54686f726f7567685048502f4f7665726c6f6164656446756e6374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/ThoroughPHP/OverloadedFunction)[![Coverage Status](https://camo.githubusercontent.com/4b929adc4bb07cc891ffbbe128f588d92943984033db07a8f5fb24bf917f1abe/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f54686f726f7567685048502f4f7665726c6f6164656446756e6374696f6e2f62616467652e737667)](https://coveralls.io/github/ThoroughPHP/OverloadedFunction)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

PHP actually does not support [function overloading](https://en.wikipedia.org/wiki/Function_overloading), as functions distinguished but name only. This is a class that helps to imulate function overloading in PHP.

Table of Contents
=================

[](#table-of-contents)

- [General usage](#general-usage)
    - [1. Simple signature](#simple-signature)
    - [2. Union types](#union-types)
    - [3. Intersection types](#intersection-types)
    - [4. Typed arrays](#typed-arrays)
    - [5. Optional parameters](#optional-parameters)

General usage
-------------

[](#general-usage)

Function cases provided as an array of callables, where key is a signature of parameters types.

### 1. Simple signature:

[](#1-simple-signature)

Parameters signature is a list of types separeted by comma.

```
    $func = new OverloadedFunction([
        'integer, integer' => function ($a, $b) { return $a + $b; },
        'string, string' => function ($a, $b) { return $a . $b; }
    ]);

    var_dump($func(1, 1)) // => 2
    var_dump($func('1', '1')) // => '11'
```

### 2. Union types:

[](#2-union-types)

Sometimes your parameter need to be of a kind, that implements not one interface, but several.

```
    $func = new OverloadedFunction([
        'ArrayAccess&Countable' => function ($i) { return true; }
    ]);

    var_dump($func(new ArrayIterator)) // => bool(true)
```

### 3. Intersection types:

[](#3-intersection-types)

Sometimes you allow parameter to be not of one type, but of several types.

```
    $func = new OverloadedFunction([
        'string|integer' => function ($i) { return true; }
    ]);

    var_dump($func(1)) // => bool(true)
    var_dump($func('1')) // => bool(true)
```

### 4. Typed arrays:

[](#4-typed-arrays)

You can restrict your parameter to be an array of elements of certain types.

```
    $func = new OverloadedFunction([
        'integer[]' => function ($arr) { return 'integer'; },
        'integer|string[]' => function ($arr) { return 'mixed'; }
    ]);

    var_dump($func([1, 2, 3])) // => string(7) "integer"
    var_dump($func([1, 2, '3'])) // => string(5) "mixed"
```

### 5. Optional parameters:

[](#5-optional-parameters)

Sometimes you allow parameter to be optional. Make sure you provide default values for such cases.

```
    $func = new OverloadedFunction([
        '?integer' => function ($i = 1) { return $i; }
    ]);

    var_dump($func(1)) // => bool(true)
    var_dump($func()) // => bool(true)
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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/4d447606cedb25aa0f2e4a57788d793bb46215aadaa5841b8ccf66f9477e5267?d=identicon)[sevavietl](/maintainers/sevavietl)

---

Top Contributors

[![Sevavietl](https://avatars.githubusercontent.com/u/1844827?v=4)](https://github.com/Sevavietl "Sevavietl (5 commits)")

---

Tags

overloadingphptypes

### Embed Badge

![Health badge](/badges/sevavietl-overloaded-function/health.svg)

```
[![Health](https://phpackages.com/badges/sevavietl-overloaded-function/health.svg)](https://phpackages.com/packages/sevavietl-overloaded-function)
```

PHPackages © 2026

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