PHPackages                             mrsuh/php-generics - 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. mrsuh/php-generics

ActiveComposer-plugin

mrsuh/php-generics
==================

PHP Generics library

1.5.8(5mo ago)2189687[1 issues](https://github.com/mrsuh/php-generics/issues)MITPHPPHP &gt;=7.4CI passing

Since Sep 13Pushed 5mo ago6 watchersCompare

[ Source](https://github.com/mrsuh/php-generics)[ Packagist](https://packagist.org/packages/mrsuh/php-generics)[ RSS](/packages/mrsuh-php-generics/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (28)Used By (0)

PHP generics written in PHP
===========================

[](#php-generics-written-in-php)

[![](https://github.com/mrsuh/php-generics/actions/workflows/tests.yml/badge.svg)](https://github.com/mrsuh/php-generics/actions/workflows/tests.yml/badge.svg)[![](https://camo.githubusercontent.com/5e60233ec48417889ae0c8ea9176473136ab5c3a69d88733bb1276a0456aa7b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d727375682f7068702d67656e65726963732e737667)](https://camo.githubusercontent.com/5e60233ec48417889ae0c8ea9176473136ab5c3a69d88733bb1276a0456aa7b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d727375682f7068702d67656e65726963732e737667)[![](https://camo.githubusercontent.com/523d7b4a501217a7e8a9c8d62cd66d3a1023879c109a6c128cdf46e38b86d354/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d727375682f7068702d67656e6572696373)](https://camo.githubusercontent.com/523d7b4a501217a7e8a9c8d62cd66d3a1023879c109a6c128cdf46e38b86d354/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d727375682f7068702d67656e6572696373)

Table of contents
-----------------

[](#table-of-contents)

- [How it works](#how-it-works)
- [Installation](#installation)
- [Monomorphization](#monomorphization)
- [Type erasure](#type-erasure)
- [Features](#features)
- [Tests](#tests)

How it works
------------

[](#how-it-works)

In a nutshell:

- parse generics classes;
- generate concrete classes based on them (you can choose `monomorphization` or `type-erasure`);
- autoload concrete classes instead of generics classes.

For example, you need to add several PHP files:

- generic class `Box`;
- class `Usage` for use generic class;
- script with composer autoload and `Usage` class.

src/Box.php

```
