PHPackages                             agorlov/php-constructor-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. agorlov/php-constructor-overloading

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

agorlov/php-constructor-overloading
===================================

Multiple constructors in PHP

1.0.1(7y ago)140[2 issues](https://github.com/agorlov/php-constructor-overloading/issues)MITPHPPHP &gt;=7.1.0

Since Sep 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/agorlov/php-constructor-overloading)[ Packagist](https://packagist.org/packages/agorlov/php-constructor-overloading)[ Docs](https://github.com/agorlov/php-constructor-overloading)[ RSS](/packages/agorlov-php-constructor-overloading/feed)WikiDiscussions master Synced 2mo ago

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

Мultiple constructors in PHP
============================

[](#мultiple-constructors-in-php)

Constructor overload PHP methods, like in Java or C++

Based on article (how to adopt this technic from Java to PHP):

For PHP &gt; 7

How to install
--------------

[](#how-to-install)

```
$ composer require agorlov/php-constructor-overloading
```

Usage example
-------------

[](#usage-example)

```
use AG\OverloadedConstructor;

final class Cash {
  /** @var int */
  private $cents;
  /** @var string */
  private $currency;

  private function constrEmpty() { // secondary
    $this->__construct(0);
  }

  private function constrCnts(int $cts) { // secondary
    $this->__construct($cts, "USD");
  }

  private function constrPrimary(int $cts, string $crn) { // primary
    $this->cents = $cts;
    $this->currency = $crn;
  }

  public function __construct() {
    // overloaded constructors invocation
    $method = (new OverloadedConstructor($this, func_get_args()))->constructor();
    $this->$method(...func_get_args());
  }

  // methods here
}

var_dump(new Cash());
```

more examples: in `example.php` and `example2.php`

Valid scalar hints
------------------

[](#valid-scalar-hints)

- array
- callable
- bool **not boolean!**
- float **not double!**
- int **not integer!**
- string
- iterable
- object

Tests
-----

[](#tests)

```
$ composer install
$ vendor/bin/phpunit OverloadedConstructorTest.php
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Total

2

Last Release

2800d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

phplibraryclassmultipleconstructorsoverloading

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/agorlov-php-constructor-overloading/health.svg)

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

###  Alternatives

[ph-7/qrcode-generator-php-class

Light QRCode PHP class (library). QR Code Generator using vCard 4.0 and the Google Chart AP

10415.5k2](/packages/ph-7-qrcode-generator-php-class)

PHPackages © 2026

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