PHPackages                             jamielsharief/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jamielsharief/struct

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

jamielsharief/struct
====================

A struct class

0.1.1(5y ago)215MITPHPPHP &gt;=7.4.0

Since Nov 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jamielsharief/struct)[ Packagist](https://packagist.org/packages/jamielsharief/struct)[ RSS](/packages/jamielsharief-struct/feed)WikiDiscussions main Synced 4d ago

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

Struct
======

[](#struct)

[![license](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)[![build](https://github.com/jamielsharief/struct/workflows/CI/badge.svg)](https://github.com/jamielsharief/struct/actions)[![coverage status](https://camo.githubusercontent.com/5c10e79d213cc422aba2b315991fbc2e42a7455dbff51baff763c50d1272dcd1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a616d69656c736861726965662f7374727563742f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/jamielsharief/struct?branch=main)

Defining a Struct
-----------------

[](#defining-a-struct)

Create a class that defines the properties.

```
use Struct\Struct;

class Contact extends Struct
{
    public string $name;
    public string $company;
    public string $email;
    public int $age;
    public bool $unsubscribed = false;
}
```

### Creating an Struct Object

[](#creating-an-struct-object)

Create and work with the Object as you normally would

```
$contact = new Contact();
$contact->name = 'Jon';
$contact->email = 'jonny@example.com';
```

You can also mass set properties by passing an array to constructor.

```
$contact = new Contact([
    'name' => 'Jon',
    'company' => 'Snow Enterprises',
    'email' => 'jon@example.com',
    'age' => 33
]);
```

### Exception Handling

[](#exception-handling)

If you try to set or get a property that does not exist, a `RuntimeException` will be thrown.

### Cloning

[](#cloning)

When `Structs` are cloned, any properties which are objects or arrays which contain objects will also be cloned.

### Initialize Hook

[](#initialize-hook)

When the `Struct` is constructed it will call `initialize` method if it is available, this is a hook incase you need to override the constructor.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

1956d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7718a059aa8ef3d6e9f6e5bd7f4d5b09b7321a059f2669e61546d1a665fbb372?d=identicon)[jamielsharief](/maintainers/jamielsharief)

---

Top Contributors

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

---

Tags

struct

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[danog/phpstruct

PHP implementation of python's struct module.

1110.1k](/packages/danog-phpstruct)

PHPackages © 2026

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