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

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

constructor-overloading/constructor-overloading
===============================================

Constructor overloading for PHP 5.3

2.0(13y ago)129MITPHPPHP &gt;=5.3.0

Since Sep 30Pushed 13y ago1 watchersCompare

[ Source](https://github.com/dorireuv/constructor-overloading)[ Packagist](https://packagist.org/packages/constructor-overloading/constructor-overloading)[ Docs](http://github.com/dorireuv/constructor-overloading)[ RSS](/packages/constructor-overloading-constructor-overloading/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Constructor Overloading
=======================

[](#constructor-overloading)

A library which allows you to have constructor overloading in PHP &gt;=5.3 projects. This is simply done using: type hint, default value and PHP doc.

Usage
-----

[](#usage)

In order to use the library it's best recommended to follow some rules. The library is looking for any private / protected methods width start with \_construct in your class. Among these methods the best candidate is picked up. In order to help the library to find the best candidate you shall follow these rules:

1. If your argument is an object, use type hint (example: function(A $a)).
2. Otherwise, the argument is a primitive and in this case if it has a default value, then you can use it to hint its type (example: function ($int = 0)).
3. Otherwise you can use PHP doc (example: @param int $int)

\*\* In case of a primitive has default value and PHP doc the default value will be preferred over the PHP doc.

Examples
--------

[](#examples)

First, in order to use the library, one must register the autoloader:

```
