PHPackages                             silvanus/structs - 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. silvanus/structs

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

silvanus/structs
================

Structs for PHP. Simple data transfer objects.

v1.1.2(3y ago)914.9k↓25%[1 PRs](https://github.com/stscoundrel/struct/pulls)MITPHPCI passing

Since Oct 20Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/stscoundrel/struct)[ Packagist](https://packagist.org/packages/silvanus/structs)[ RSS](/packages/silvanus-structs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

Structs
=======

[](#structs)

Structs for PHP. Simple data transfer objects.

### Install

[](#install)

Via Composer:

`composer require silvanus/structs`

To use autoloading mechanism, you must include `vendor/autoload.php` file in your code.

### Motivation

[](#motivation)

PHP does not have real structs. They are feature in many other languages like C++, Rust or Go. Typescripts interfaces also bear resemblence to structs. Structs would serve a purpose for simple data that has a shape, like data transfer objects.

In PHP you can't demand properties with Interfaces, only methods. Therefore interfaces for struct-like objects do not make much sense. But if you just use a class that has public properties, you'll still let clients just declare new properties on the fly. It would be preferable to keep the shape of data just the way the struct was defined.

This library aims to solve this by providing AbstractStruct class with sensible defaults to stop dynamically assigning new or incorrect class properties/members.

### Usage

[](#usage)

Declare new struct.

```
