PHPackages                             cloud-io/struct - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. cloud-io/struct

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

cloud-io/struct
===============

Generate immutable typed structs from arrays, JSON, XML, YAML and PHP configuration files.

v1.0.4(1mo ago)00MITPHPPHP &gt;=8.4

Since Jun 3Pushed 1mo agoCompare

[ Source](https://github.com/claudioacioli/struct)[ Packagist](https://packagist.org/packages/cloud-io/struct)[ Docs](https://github.com/claudioacioli/struct)[ RSS](/packages/cloud-io-struct/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (6)Used By (0)

cloud-io/struct
===============

[](#cloud-iostruct)

Converts associative arrays, JSON, XML, YAML and PHP configuration files into dynamically generated immutable structs, without the need to declare classes.

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

[](#installation)

```
composer require cloud-io/struct
```

Why use it?
-----------

[](#why-use-it)

- Property navigation (`$user->address->city`)
    - Immutable objects (`readonly`)
    - Automatic recursive conversion
    - Reduces the need for boilerplate DTOs
    - Per-shape class caching
    - Supports arrays, JSON, XML, YAML and PHP config files

How it works
------------

[](#how-it-works)

When given an associative array, `struct()` dynamically generates a `final readonly` class with public properties corresponding to the array keys. Nested associative arrays are recursively converted. Indexed arrays are preserved as arrays.

Generated classes are cached per shape + namespace. After the first generation, new instances of the same shape reuse the same class without executing `eval` again.

Usage
-----

[](#usage)

```
use function io\struct;

$user = struct([
    'name'    => 'Claudio',
    'address' => [
        'city' => 'Brasília',
    ],
]);

echo $user->address->city;
```

```
use function io\file_struct;

$config = file_struct('config.json');

echo $config->database->host;
```

```
$response = json_struct($json);

echo $response->customer->address->city;
```

```
$users = json_struct('[
    {"name":"John"},
    {"name":"Mary"}
]');

echo $users[0]->name;
echo $users[1]->name;
```

Functions
---------

[](#functions)

FunctionInput`struct(array $data)`PHP array`json_struct(string $json)`JSON string`xml_struct(string $xml)`XML string`yaml_struct(string $yaml)`YAML string`require_struct(string $file)``.php` file returning an array`file_struct(string $file)``.json`, `.xml`, `.yaml`, `.yml`, `.php`All functions accept an optional second parameter `?string $namespace` to control the namespace of the generated classes.

Performance
-----------

[](#performance)

Generated classes are cached by shape and namespace.

The first call for a new shape generates a readonly class dynamically. Subsequent calls reuse the existing class and only instantiate new objects.

Limitations
-----------

[](#limitations)

**XML:** conversion uses a SimpleXML → JSON roundtrip. XML attributes are nested under the `@attributes` key. Mixed-content nodes and repeated sibling elements may produce unexpected shapes.

**YAML:** requires the `pecl/yaml` extension installed in PHP.

**Property collision:** distinct keys that normalize to the same property name throw `InvalidArgumentException`. e.g. `foo-bar` and `foo_bar` both become `foo_bar`.

**In-memory shape cache:** the shape cache is per process/worker. Applications with many distinct dynamic shapes will see proportional memory growth.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

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

Total

5

Last Release

51d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2e071a6a1d5339facd1f4d3bae3d3f79c96dc9b58502bcf3cf66a39193cf429?d=identicon)[cloud-io](/maintainers/cloud-io)

---

Top Contributors

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

---

Tags

jsonxmlyamldtoimmutablestruct

### Embed Badge

![Health badge](/badges/cloud-io-struct/health.svg)

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

###  Alternatives

[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

1.0k13.8M189](/packages/hassankhan-config)[thunderer/serializard

Flexible serializer

2667.9k1](/packages/thunderer-serializard)

PHPackages © 2026

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