PHPackages                             tebru/php-type - 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. tebru/php-type

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

tebru/php-type
==============

A type wrapper for PHP that support generic syntax

v0.1.7(6y ago)3189.0k↓26.5%15MITPHPPHP &gt;= 7.1CI failing

Since Apr 19Pushed 6y ago2 watchersCompare

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

READMEChangelog (2)Dependencies (1)Versions (10)Used By (5)

Php Type
========

[](#php-type)

[![Build Status](https://camo.githubusercontent.com/44d03a79047d0386d51feed76df68097b180f0b75781c45c680dd207e4ed9f13/68747470733a2f2f7472617669732d63692e6f72672f74656272752f7068702d747970652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tebru/php-type)[![Code Coverage](https://camo.githubusercontent.com/138f6295867f460d93034cca8ef5a8c5f8ab10da56f60da666c3115d0759c28f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f7068702d747970652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/php-type/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6577ae83b81ba51dd712b32211b7fb13bd8dba261ef03668c5da275fdd203556/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f7068702d747970652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/php-type/?branch=master)

This library wraps a type string and provides an API around getting information about the type. It also supports generic type syntax.

General Usage
-------------

[](#general-usage)

The simplest way is to instantiate a new TypeToken and pass in the type.

```
new TypeToken('string');
```

The class also normalizes the type:

```
$typeShort = new TypeToken('int');
$typeLong = new TypeToken('integer');

$typeShort->getRawType(); // 'integer'
$typeLong->getRawType(); // 'integer'

$typeShort->getPhpType(); // 'integer'
$typeLong->getPhpType(); // 'integer'

$typeShort->isInteger(); // true
$typeLong->isInteger(); // true
```

Any of the core php types are supported as well as `?` which represents a wildcard type. This can be used if the type is unknown at the time the type is instantiated. All of the possible types are represented as constants on the class.

Classes also work the same

```
$type = new TypeToken(\My\Foo::class);

$type->getRawType(); // 'My\Foo'
(string)$type; // 'My\Foo'
$type->getPhpType(); // 'object'
$type->isObject(); // true
$type->isA(\My\Foo::class); // true
```

`->isA()` checks the instantiated type's parent classes and interfaces in addition to the passed in class name.

You can also use generic syntax with angle brackets.

```
$type = new TypeToken('My\Foo');

$type->getRawType(); // 'My\Foo'
(string)$type; // 'My\Foo'
$type->getPhpType(); // 'object'
$type->isObject(); // true
$type->isA(\My\Foo::class); // true

$generics = $type->getGenerics();
(string)$generics[0]; // 'string'
(string)$generics[1]; // 'My\Foo2'
```

Calling `->getGenerics()` will return an array of TypeToken objects.

Nested generics work the same way

```
new TypeToken('array');
```

This could represent an array with string keys and all values are an array of integers.

If you have a variable, you can get the type using the static factory method

```
TypeToken::createFromVariable($variable);
```

This uses the singleton method `::create()` which will return the same instance on duplicate types.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.2% 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 ~130 days

Recently: every ~159 days

Total

8

Last Release

2405d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1831497?v=4)[Nate Brunette](/maintainers/natebrunette)[@natebrunette](https://github.com/natebrunette)

---

Top Contributors

[![natebrunette](https://avatars.githubusercontent.com/u/1831497?v=4)](https://github.com/natebrunette "natebrunette (15 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tebru-php-type/health.svg)

```
[![Health](https://phpackages.com/badges/tebru-php-type/health.svg)](https://phpackages.com/packages/tebru-php-type)
```

###  Alternatives

[eternicode/bootstrap-datepicker

A datepicker for Bootstrap

12.7k543.8k6](/packages/eternicode-bootstrap-datepicker)[netojose/laravel-bootstrap-4-forms

Bootstrap 4 form builder for Laravel 5

182115.3k](/packages/netojose-laravel-bootstrap-4-forms)[nette/coding-standard

41930.0k15](/packages/nette-coding-standard)[wilon/php-number2chinese

PHP数字转为汉字描述、人民币大写方法。

14632.0k1](/packages/wilon-php-number2chinese)[hmaus/drafter-php

PHP wrapper around drafter binary

32127.0k5](/packages/hmaus-drafter-php)[laravel-enso/charts

Server-side data builder for Chart.js, with a VueJS component for the frontend.

1761.1k7](/packages/laravel-enso-charts)

PHPackages © 2026

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