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

ActiveLibrary

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 1mo ago

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 32% of packages

Maintenance38

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

551d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/727feb0c5668769f8878a839a16dd4777bcb2604bc9ca197ed74527ffd159ccb?d=identicon)[xuebincui](/maintainers/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

[moment/moment

Parse, validate, manipulate, and display dates in JavaScript.

48.1k2.1M37](/packages/moment-moment)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k34.5M216](/packages/smalot-pdfparser)[fightbulc/moment

Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js

9693.2M10](/packages/fightbulc-moment)[parse/php-sdk

Parse PHP SDK

8101.1M11](/packages/parse-php-sdk)[enqueue/dsn

Parse DSN

12525.5M45](/packages/enqueue-dsn)[gabrielelana/byte-units

Library to parse, format and convert byte units

1672.2M19](/packages/gabrielelana-byte-units)

PHPackages © 2026

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