PHPackages                             php-strict/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. php-strict/struct

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

php-strict/struct
=================

Implementation of composite type for PHP.

v1.0.0(7y ago)09911GPL-2.0-or-laterPHPPHP ^7.1

Since Mar 26Pushed 6y ago1 watchersCompare

[ Source](https://github.com/php-strict/struct)[ Packagist](https://packagist.org/packages/php-strict/struct)[ Docs](https://github.com/php-strict/struct)[ RSS](/packages/php-strict-struct/feed)WikiDiscussions master Synced 3d ago

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

Struct
======

[](#struct)

[![Software License](https://camo.githubusercontent.com/e1514dd3f2095dbf68a0008ae62a631142953ad2e86aa94c504343f2c2c191da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c2d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Build Status](https://camo.githubusercontent.com/ccfa5b28e883c84d0391bae39d20cce018afa216d6b16d908fbe80679ffe2e9e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d7374726963742f7374727563742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/php-strict/struct)[![codecov](https://camo.githubusercontent.com/18f3d345e1d56ed83acc34e9bd56e2c5fba2e395539bb90d7e3d6ca7344d8595/68747470733a2f2f636f6465636f762e696f2f67682f7068702d7374726963742f7374727563742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/php-strict/struct)[![Codacy Badge](https://camo.githubusercontent.com/6bde460a1099714b1090b37a282276061a51c72948e46ab6838796f756371116/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3932666630353433326331633463316238353939653166353365653563313561)](https://www.codacy.com/app/php-strict/struct?utm_source=github.com&utm_medium=referral&utm_content=php-strict/struct&utm_campaign=Badge_Grade)

Implementation of composite type for PHP.

Contains methods to create from associated array, JSON string or another Struct, with/without type cast.

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

[](#requirements)

- PHP &gt;= 7.1

Install
-------

[](#install)

Install with [Composer](http://getcomposer.org):

```
composer require php-strict/struct
```

Usage
-----

[](#usage)

Define your own composite type by extending Struct class:

```
use PhpStrict\Struct\Struct

class Book extends Struct
{
    /**
     * @var string
     */
    public $author = '';

    /**
     * @var string
     */
    public $title = '';

    /**
     * @var string
     */
    public $isbn = '';

    /**
     * @var int
     */
    public $pages = 0;

    /**
     * @var bool
     */
    public $publicated = false;

    /**
     * @var array
     */
    public $tags = [];
}
```

Now you can fill your strcuture with data:

```
//book with classic assign data to class fields
$book1 = new Book();
$book1->author = 'Author Name';
$book1->title = 'Book title 1';
$book1->isbn = '000-0-000-00000-0';
$book1->pages = 240;
$book1->publicated = true;
$book1->tags = ['fantastic', 'space', 'detective'];

//another book with data through array
$book2 = new Book([
    'author' => 'Author Name',
    'title' => 'Book title 2',
    'isbn' => '000-0-000-00000-0',
    'pages' => 156,
    'publicated' => true,
    'tags' => ['drama', 'nature'],
]);

//another book with data through JSON
$json = '{"author":"Author Name","title":"Book title 3","isbn":"000-0-000-00000-0","pages":156,"publicated":true,"tags":["comedy","city"]}';
$book3 = new Book($json);

//book, based on existing book
$book4 = new Book($book1);
$book4->title = 'Book title 4';
```

See examples dir.

Tests
-----

[](#tests)

To execute the test suite, you'll need [Codeception](https://codeception.com/).

```
vendor\bin\codecept run
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

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

2607d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f404fa292f952ba0429cfe11f608e982e0d9d645f2ac864c53abee7f71dff2b?d=identicon)[enikeishik](/maintainers/enikeishik)

![](https://www.gravatar.com/avatar/cd3e4de19690d7855584ae697f09ec89fe44cef55e4f4b201d89945d1b3857d1?d=identicon)[phpstrict](/maintainers/phpstrict)

---

Top Contributors

[![enikeishik](https://avatars.githubusercontent.com/u/2239913?v=4)](https://github.com/enikeishik "enikeishik (31 commits)")

---

Tags

phpphp-libraryphp7structstructurephpstructurestrictstruct

###  Code Quality

TestsCodeception

### Embed Badge

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

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

###  Alternatives

[strictus/strictus

Strict Typing for local variables in PHP

1606.9k](/packages/strictus-strictus)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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