PHPackages                             codemagpie/array2object - 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. codemagpie/array2object

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

codemagpie/array2object
=======================

A high performance, Supports converting array into object and object into array, easy to use

1.0.1(3y ago)01111MITPHPPHP &gt;=7.4

Since May 25Pushed 3y ago1 watchersCompare

[ Source](https://github.com/codemagpie/php-lib-array2object)[ Packagist](https://packagist.org/packages/codemagpie/array2object)[ RSS](/packages/codemagpie-array2object/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (3)Used By (1)

Array To Object
===============

[](#array-to-object)

Introduction
------------

[](#introduction)

Supports converting array into object and object into array, easy to use

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

[](#installation)

```
composer require codemagpie/array2object
```

Usage1
------

[](#usage1)

Only need to declare the class property type:

```
use CodeMagpie\ArrayToObject\AbstractBaseObject

class User extends AbstractBaseObject
{
    public string $name;

    public int $age;

    public User $child;
    /**
     * @var User[]
     */
    public array $children;
}
```

To use:

```
$arr = [
    'name' => 'test',
    'age' => '17',
    'child' => [
        'name' => 'test1',
        'age' => '17',
    ],
    'children' => [
        [
            'name' => 'test2',
            'age' => '17',
        ],
    ],
];
$user = new User($arr);
// if the user object does not extend AbstractBaseObject, you should use:
// $user = new User();
// \CodeMagpie\ArrayToObject\ArrayToObjectBuilder::create()->bind($user);
// echo \CodeMagpie\ArrayToObject\Utils\DataHelper::objectToArray($user); // Array
echo $user->name; // test
echo $user->age; // 17
echo $user->child->name; // test1
echo $user->children[0]->name; // test2
echo $user->toArray() //Array. if extend ArrayToObjectBuilder
```

Usage2
------

[](#usage2)

Only need declare the property type on the class's annotation:

```
use CodeMagpie\ArrayToObject\AbstractLightBaseObject

/**
 * @property string $name
 * @property int $age
 * @property User $child
 * @property User[] $children
 */
class User extends AbstractLightBaseObject
{
}
```

To use:

```
$arr = [
    'name' => 'test',
    'age' => '17',
    'child' => [
        'name' => 'test1',
        'age' => '17',
    ],
    'children' => [
        [
            'name' => 'test2',
            'age' => '17',
        ],
    ],
];
$user = new User($arr);
// if the user object does not extend AbstractLightBaseObject, you should use:
// $user = new User();
// \CodeMagpie\ArrayToObject\ArrayToObjectBuilder::createFormPropertyDocParser()->bind($user);
// echo \CodeMagpie\ArrayToObject\Utils\DataHelper::objectToArray($user);// Array
echo $user->name; // test
echo $user->age; // 17
echo $user->child->name; // test1
echo $user->children[0]->name; // test2
echo $user->toArray() //Array. if extend AbstractLightBaseObject
```

Usage performance comparison
----------------------------

[](#usage-performance-comparison)

proportiontime consumptionmemory usagememory consumptionusage1:usage24:12:3≈ 1:1

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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

Total

2

Last Release

1453d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/278a94dbba96f0aeb8d25818d8b9e37322f2649374a6a23f41144058c24a49c2?d=identicon)[codemagpie](/maintainers/codemagpie)

---

Tags

arrayconvertobjectArray2ObjectcodemagpieArray to object

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[yzen.dev/plain-to-class

Class-transformer to transform your dataset into a structured object

16293.9k6](/packages/yzendev-plain-to-class)[jasny/dotkey

Dot notation access for objects and arrays

14219.5k6](/packages/jasny-dotkey)[michaldudek/foundation

A set of useful PHP classes.

13111.9k13](/packages/michaldudek-foundation)[peridot-php/object-path

A string syntax to fetch values from array and object hierarchies

1053.6k1](/packages/peridot-php-object-path)

PHPackages © 2026

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