PHPackages                             unicon/unicon - 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. unicon/unicon

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

unicon/unicon
=============

Universal PHP variable converter. The main feature is converting arrays to an object of given class. In this case, Unicon follows PhpDoc annotations, works recursively to create the object's properties.

1.0.0(2y ago)13.1k1GPL-2.0-onlyPHPPHP &gt;=8.1

Since Jan 10Pushed 2y ago2 watchersCompare

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

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

Unicon
======

[](#unicon)

Unicon is universal PHP variable converter. The main feature is converting arrays to an object of given class. In this case, Unicon follows PhpDoc annotations, works recursively to create the object's properties.

See [unicon/yaml](https://packagist.org/packages/unicon/yaml) - one of possible implementations. It converts YAML file to an object of given class.

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

[](#installation)

`composer require unicon/unicon`

Usage
-----

[](#usage)

ConverterFactory creates a converter for the given target type. Target type may be class FQN, standard php type or types union. Once created, the converter may be used few times.

```
$converter = ConverterFactory::create($targetType);
```

Converter returns ConversionValue|AbstractError. ConversionValue::value contains converted value. It may be null if target type is nullable (null|\\MyNamespace\\MyClass): in this case null is also success result.

```
$result = $converter->convert($source);
```

Example
-------

[](#example)

```
namespace MyNamespace;

class SimpleClass
{
    private ?string $stringProperty;
    private false|int $falseOrIntegerProperty;
    private \DateTimeInterface $date;
    /** @var bool */
    private mixed $boolPhpDocProperty;
}

$converter = ConverterFactory::create(SimpleClass::class);
$result = $converter->convert([
    'stringProperty' => 'test',
    'falseOrIntegerProperty' => 0,
    'date' => '2013-01-13 12:00:00',
    'boolPhpDocProperty' => 1
]);
```

Result:```
object(Unicon\Unicon\ConversionValue)#11 (1) {
  ["value"]=>
  object(MyNamespace\SimpleClass)#14 (4) {
    ["stringProperty":"MyNamespace\SimpleClass":private]=>
    string(4) "test"
    ["falseOrIntegerProperty":"MyNamespace\SimpleClass":private]=>
    int(0)
    ["date":"MyNamespace\SimpleClass":private]=>
    object(DateTimeImmutable)#29 (3) {
      ["date"]=>
      string(26) "2013-01-13 12:00:00.000000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(11) "Europe/Riga"
    }
    ["boolPhpDocProperty":"MyNamespace\SimpleClass":private]=>
    bool(true)
  }
}
```

Settings
--------

[](#settings)

ConverterFactory::create has the second optional parameter of ConversionSettings class:

```
ConverterFactory::create(
    string $type = 'mixed',
    ConversionSettings $settings = new ConversionSettings()
)
```

You can create your ConversionSettings and configure it for your needs:

```
$settings = new ConversionSettings();
$settings->allowHumanConversion();
$settings->allowForcedConversion();
$settings->setStringToDateFormats(['Y-m-d H:i:s']);
$settings->setDateToStringFormat('Y-m-d H:i:s');
$settings->allowNullToEmptyArrayConversion();
$settings->checkIfAllPropertiesAreInitialized();
```

Conversion priorities
---------------------

[](#conversion-priorities)

1. Strict match (1 for int)
2. Gentle casting ('1' for int)
3. Forced casting if turned on (1.1 to 1 for int)

This affect the conversion if the property has few conversion options. For example:

`null``0``'0'``int``0 ``0``0``?int``null``0``0``null|int|string``null``0``'0'``?string``null``'0'``'0'``string``''``'0'``'0'`

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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

Unknown

Total

1

Last Release

859d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5369c71152f0feb0c57d12044c87c7f8be9c4640586b042629a6c50638d4e2e8?d=identicon)[sashabo](/maintainers/sashabo)

---

Top Contributors

[![xbndrv](https://avatars.githubusercontent.com/u/151878218?v=4)](https://github.com/xbndrv "xbndrv (23 commits)")

### Embed Badge

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

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

###  Alternatives

[phpdocumentor/reflection-docblock

With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.

9.4k722.2M1.2k](/packages/phpdocumentor-reflection-docblock)[icanhazstring/composer-unused

Show unused packages by scanning your code

1.7k7.0M188](/packages/icanhazstring-composer-unused)[spatie/typescript-transformer

This is my package typescript-transformer

3706.5M16](/packages/spatie-typescript-transformer)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[typhoon/reflection

Static PHP reflection with phpDoc support

3848.6k4](/packages/typhoon-reflection)

PHPackages © 2026

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