PHPackages                             aveiv/mixed-value - 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. aveiv/mixed-value

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

aveiv/mixed-value
=================

MixedValue provides easy array access and the ability to convert/cast values

v0.3.2(4y ago)3104.9k↑57.8%1MITPHPPHP ^7.4|^8.0

Since Aug 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/aveiv/mixed-value)[ Packagist](https://packagist.org/packages/aveiv/mixed-value)[ Docs](https://github.com/aveiv/mixed-value)[ RSS](/packages/aveiv-mixed-value/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (1)

[![Build Status](https://camo.githubusercontent.com/840d99722042fee76bf5dcd69d824e6ba5a76003907b2ed87eb72b9ed66765ac/68747470733a2f2f7472617669732d63692e636f6d2f61766569762f6d697865642d76616c75652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/aveiv/mixed-value) [![Latest Stable Version](https://camo.githubusercontent.com/42f513d620aaad782178a5d7c47ee391a26241d3d03b575a22d99cbca1fbddd2/68747470733a2f2f706f7365722e707567782e6f72672f61766569762f6d697865642d76616c75652f76)](//packagist.org/packages/aveiv/mixed-value) [![Total Downloads](https://camo.githubusercontent.com/cb796bd0a710004370a1563007f6737b901ea262787f1632f305abbe603fbc3a/68747470733a2f2f706f7365722e707567782e6f72672f61766569762f6d697865642d76616c75652f646f776e6c6f616473)](//packagist.org/packages/aveiv/mixed-value) [![License](https://camo.githubusercontent.com/18206b422f11af81cf13ca47c26a1b44c8b5f60818d1b143f7e30428843e4b13/68747470733a2f2f706f7365722e707567782e6f72672f61766569762f6d697865642d76616c75652f6c6963656e7365)](//packagist.org/packages/aveiv/mixed-value)

MixedValue provides easy array access and the ability to convert/cast values.

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

[](#installation)

```
composer require aveiv/mixed-value

```

Access to array
---------------

[](#access-to-array)

```
$mixed = new MixedValue([
    'good' => [
        'path' => 'value',
    ]
]);

$mixed['good']['path']->getValue(); // returns "value"
$mixed['invalid']['path']->getValue(); // throws MissingValueException

$mixed['invalid']['path']->findValue(); // returns null
$mixed['invalid']['path']->findValue() ?? 'default'; // returns "default"
```

Checking value types
--------------------

[](#checking-value-types)

```
$mixed = new MixedValue([
    'array_val' => [],
    'bool_val' => true,
    'float_val' => 1.0,
    'int_val' => 1,
    'numeric_val' => '99.99',
    'str_val' => 'string',
]);

$mixed['array_val']->isArray()->getValue(); // returns []
$mixed['bool_val']->isBool()->getValue(); // returns true
$mixed['float_val']->isFloat()->getValue(); // returns 1.0
$mixed['int_val']->isInt()->getValue(); // returns 1
$mixed['numeric_val']->isNumeric()->getValue(); // returns '99.99'
$mixed['str_val']->isString()->getValue(); // returns "string"

$mixed['str_val']->isInt()->getValue(); // throws UnexpectedValueException
```

Converting/casting values
-------------------------

[](#convertingcasting-values)

Default converters use PHP casting rules. UnexpectedValueException is thrown if a value cannot be converted.

```
$mixed = new MixedValue([
    'id' => '99',
    'name' => 'Mary',
    'birthdate' => '1990-01-01',
    'balance' => '999.99',
    'isActive' => 1,

    'array_data' => [],
]);

$mixed['id']->toInt()->getValue(); // returns 99
$mixed['name']->toString()->getValue(); // returns "Mary"
$mixed['birthdate']->toDateTime()->getValue(); // returns DateTime("1990-01-01")
$mixed['balance']->toFloat()->getValue(); // returns 999.99
$mixed['isActive']->toBool()->getValue(); // returns true

$mixed['array_data']->toString()->getValue(); // throws UnexpectedValueException
```

Processing array elements
-------------------------

[](#processing-array-elements)

```
$mixed = new MixedValue([
    'mixed_arr' => [1, 2, '3', 4, 5],
]);

$mixed['mixed_arr']
    ->map(fn(MixedValue $el) => $el->toInt()->getValue())
    ->getValue(); // returns [1, 2, 3, 4, 5]
```

Use custom value processors
---------------------------

[](#use-custom-value-processors)

```
class StripSpacesProcessor implements ValueProcessorInterface
{
    public function __invoke($value)
    {
        if (!is_string($value)) {
            throw new UnexpectedValueException('Value must be a string');
        }
        return str_replace(' ', '', $value);
    }
}

$mixed = new MixedValue([
    'bad_float' => '9 999.99',
]);
$mixed->registerValueProcessor('stripSpaces', new StripSpacesProcessor());

$mixed['bad_float']->stripSpaces()->toFloat()->getValue(); // return 9999.99
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

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

Recently: every ~120 days

Total

6

Last Release

1627d ago

PHP version history (2 changes)v0.1.0PHP ^7.4

v0.3.1PHP ^7.4|^8.0

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

typearrayconvertcastmixed

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aveiv-mixed-value/health.svg)

```
[![Health](https://phpackages.com/badges/aveiv-mixed-value/health.svg)](https://phpackages.com/packages/aveiv-mixed-value)
```

###  Alternatives

[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)[wplake/typed

Lightweight PHP utility for seamless type-casting and data retrieval from dynamic variables, arrays, and objects.

231.0k](/packages/wplake-typed)

PHPackages © 2026

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