PHPackages                             parse-to-object/parse-to-object - 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. parse-to-object/parse-to-object

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

parse-to-object/parse-to-object
===============================

parse-to-object - parse array/object to a specified object.

0.1.0(1y ago)14MITPHPPHP &gt;=8.2

Since Nov 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/xuebincui/parse-to-object)[ Packagist](https://packagist.org/packages/parse-to-object/parse-to-object)[ RSS](/packages/parse-to-object-parse-to-object/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

ParseToObject
=============

[](#parsetoobject)

ParseToObject is a simple library to parse param (array/object) into object.

Required
--------

[](#required)

php &gt;= 8.2

Usage
-----

[](#usage)

```
use ParseToObject\ParseToObject;
use ParseToObject\ParseAttr;

enum TestType: int {
    case Normal = 0;
    case Api = 1;
}

class TestSubOject {
    #[ParseAttr]
    public int $id;
    #[ParseAttr]
    public ?string $name;
}

class TestOject {
    #[ParseAttr(name: "id")]
    public int $id;
    #[ParseAttr]
    public ?string $name;
    #[ParseAttr]
    public $age;
    #[ParseAttr]
    public TestType $type = TestType::Normal;
    #[ParseAttr(name: "sub")]
    public ?TestSubOject $subOject = null;
    #[ParseAttr(className: TestSubOject::class)]
    public array $subList = [];
    #[ParseAttr]
    public array $numberList = [];
    #[ParseAttr(name: "delimiterStr", sourceType: "delimiter-str", delimiter: "|")]
    public array $delimiterList = [];
    #[ParseAttr(name: "jsonStr", sourceType: "json-str")]
    public ?TestSubOject $jsonObj = null;

    public int $sex;

    use ParseToObject;
}
```

```
$sub = [
    'id' => 11,
    'name' => 'TestSub'
];
$params = [
    'id' => 1,
    'name' => 'Test',
    'age' => 20,
    'type' => 1,
    'sub' => $sub,
    'subList' => [
        [
            'id' => 12,
            'name' => 'TestSub12'
        ],
        [
            'id' => 13,
            'name' => 'TestSub13'
        ]
    ],
    'numberList' => [1, 2, 3],
    'delimiterStr' => 'a|b|c',
    'jsonStr' => json_encode($sub),
];
$testOject = TestOject::from($params);
or
ParseToObject\Parser::make(TestOject::class, $params)->convertToObject();
```

ParseAttr Attribute
-------------------

[](#parseattr-attribute)

attrtypedescriptiondefault**name**stringparam namenull**type**stringname data typenull**isDefault**boolIs there a default valuefalse**default**default valuenull**required**boolparam is requiredfalse**className**stringwhen type is 'array' and className is not null, className is the class name of array item.null**sourceType**stringsource type, string (json-str,delimiter-str).null**delimiter**stringValid when sourceType is 'delimiter-str'.","Exception
---------

[](#exception)

```
use ParseToObject\Exceptions\ParamException;
use ParseToObject\Exceptions\ParamErrCode;

$params = [
    'id' => null,
    'name' => 'Test',
    'age' => 20,
];
try {
    $testOject = TestOject::from($params);
} catch (ParamException $e) {
    var_dump($e->getName()); // id
    var_dump($e->getErrCode()); // ParamErrCode::NotNull
    var_dump($e->getMessage()); // param id is cannot be null
}
```

```
enum ParamErrCode: int {
    case Required = 1; // 参数必须存在
    case Missing = 2; // 参数不存在
    case NotNull = 3; // 值不能为null
    case ValueInvalid = 4; // 值无效
}
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

597d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15667294?v=4)[xuebincui](/maintainers/xuebincui)[@xuebincui](https://github.com/xuebincui)

---

Top Contributors

[![xuebincui](https://avatars.githubusercontent.com/u/15667294?v=4)](https://github.com/xuebincui "xuebincui (6 commits)")

---

Tags

parseparse-to-object

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/parse-to-object-parse-to-object/health.svg)

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

###  Alternatives

[enqueue/dsn

Parse DSN

12526.6M63](/packages/enqueue-dsn)[gabrielelana/byte-units

Library to parse, format and convert byte units

1752.3M21](/packages/gabrielelana-byte-units)[soul/address-parse

收货地址解析，成功率99%以上，支持（身份证号，电话，座机，区号，省市区街道地址)

405.6k](/packages/soul-address-parse)[lawondyss/moment-php

MomentPHP is library for parsing, manipulating and formatting dates.

1419.2k](/packages/lawondyss-moment-php)[luka-dev/headless-task-server-php

Helper for sending requests to luka-dev/headless-task-server

1010.0k](/packages/luka-dev-headless-task-server-php)[simplon/url

Simple URL

115.5k2](/packages/simplon-url)

PHPackages © 2026

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