PHPackages                             michaelrushton/types - 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. michaelrushton/types

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

michaelrushton/types
====================

A PHP library to manipulate arrays, numbers, and strings using a fluent interface.

00PHP

Since Jun 26Pushed 1w ago1 watchersCompare

[ Source](https://github.com/MichaelRushton/php-types)[ Packagist](https://packagist.org/packages/michaelrushton/types)[ RSS](/packages/michaelrushton-types/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP-Types
=========

[](#php-types)

A PHP library to manipulate arrays, numbers, and strings using a fluent interface.

Installation
------------

[](#installation)

```
composer require michaelrushton/types
```

Documentation
-------------

[](#documentation)

The classes in this library are wrappers for the native [array](https://www.php.net/manual/en/ref.array.php), [math](https://www.php.net/manual/en/ref.math.php), and [string](https://www.php.net/manual/en/ref.strings.php) functions. Method names mostly use the native function names but with any underscores and `str` or `array` prefixes removed.

```
use function MichaelRushton\Types\str;

echo str('this is a string')
->ucwords()
->replace(' ', '')
->lcfirst();
// thisIsAString
```

Two notable exceptions to the naming convention in the `Arr` class are `advance` which is used to call `next` and `contains` which is used to call `in_array`.

```
$arr = arr([1, 2, 3]);

$arr->contains(1);
// true

$arr->advance();
// num(2)
```

Methods are chainable even when switching between arrays, numbers, and strings.

```
echo str('here are words')
->explode(' ')
->merge(['and', 'more', 'words'])
->implode(' ');
// here are words and more words
```

Some methods are not chainable by default.

```
echo str('example')->len();
// 7
```

These methods can be made to be chainable by passing a final `$return` argument by reference.

```
echo str('example')->len($length);
// example

echo $length->add(1);
// 8
```

Invoke the object as a function to return the underlying value.

```
$str = str('example')->toupper()();

var_dump($str);
// string(7) 'EXAMPLE'
```

If the final method in the chain does not require any arguments then calling it as a property will also return the underlying value.

```
$str = str('example')->toupper;

var_dump($str);
// string(7) 'EXAMPLE'
```

Use the `through` method to pass the object through a callback, returning the object.

```
use MichaelRushton\Types\Str;

$str = str('this is a string')->through(function (Str $str)
{
    $str->ucwords()
    ->replace(' ', '')
    ->lcfirst();
});
```

Use the `pipe` method to pipe the object through a callback, returning the given value.

```
use MichaelRushton\Types\Str;

$length = str(' test ')->pipe(function (Str $str)
{
    return $str->trim()->len;
});
```

Arithmetic in other bases
-------------------------

[](#arithmetic-in-other-bases)

The `Num` class can work in any base between 2 and 36 by passing the base as the second argument. When working in anything other than base 10 the number will be returned as a string.

```
$num = num('-f.ab', 16)
->mul(10); // multiply by 10 as a base 10 number

var_dump($num());
// string(6) '-9c.ae'

$num = num('-f.ab', 16)
->mul(num(10, 16)); // multiply by 10 as a base 16 number

var_dump($num());
// string(5) '-fa.b'
```

The `bin`, `oct`, `dec`, and `hex` methods can be used to convert the number to base 2, base 8, base 10, and base 16 respectively. The `baseconvert` method can be used to convert the number to the given base.

```
$num = num('-f.ab', 16);

echo $num->bin;
// -1111.10101011

echo $num->oct;
// -17.526

echo $num->dec;
// -15.66796875

echo $num->hex;
// -f.ab

echo $num->baseconvert(36);
// -f.o1or
```

API reference
-------------

[](#api-reference)

[Arr](docs/arr.md)
[Num](docs/num.md)
[Str](docs/str.md)

Extending the library
---------------------

[](#extending-the-library)

To extend the library call the `extend` static method on any of the classes, passing it a child class.

```
use MichaelRushton\Types\Str;

Str::extend(new class extends Str
{

    public function camelcase(): static
    {

        return $this->ucwords()
        ->replace(' ', '')
        ->lcfirst();

    }

});

echo str('this is a string')->camelcase;
// thisIsAString
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity11

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://avatars.githubusercontent.com/u/49325097?v=4)[michaelrushton](/maintainers/michaelrushton)[@MichaelRushton](https://github.com/MichaelRushton)

---

Top Contributors

[![MichaelRushton](https://avatars.githubusercontent.com/u/49325097?v=4)](https://github.com/MichaelRushton "MichaelRushton (12 commits)")

### Embed Badge

![Health badge](/badges/michaelrushton-types/health.svg)

```
[![Health](https://phpackages.com/badges/michaelrushton-types/health.svg)](https://phpackages.com/packages/michaelrushton-types)
```

PHPackages © 2026

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