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

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

able/struct
===========

phpABLE struct data type implementation library

v1.1.1(4y ago)11.1k1MITPHPPHP &gt;=8.0.0CI failing

Since May 17Pushed 4y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (3)Used By (1)

Introduction
------------

[](#introduction)

The phpABLE struct emulation library.

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

[](#requirements)

- PHP &gt;= 8.0.0
- [able/helpers](https://github.com/phpable/helpers)
- [able/prototypes](https://github.com/phpable/prototypes)
- [able/exceptions](https://github.com/phpable/exceptions)
- [able/reglib](https://github.com/phpable/reglib)

Features
--------

[](#features)

The mission of this library is to emulate the structures' behavior most naturally.

Install
-------

[](#install)

There's a simple way to install the `able/struct` package via [composer](http://getcomposer.org):

```
composer require able/struct
```

Usage
-----

[](#usage)

### Basic

[](#basic)

Let's try to declare a structure:

```
use \Able\Struct;

class MyStruct extends AStruct {

	protected static $Prototype = ['field1', 'field2'];
}
```

Now we can use it in a siple way:

```
$Struct = new MyStruct(1,2);
echo $Struct->field1;

//> 1
```

It's also possible to fill fields later:

```
$Struct = new MyStruct();

$Struct->field1 = "Test string!";
echo $Struct->field1;

//> Test string!
```

### Mutators

[](#mutators)

Mutators are pretty helpful in case it needed to customize the default structure behavior.

```
use \Able\Struct;

class MyStruct extends AStruct {

	protected static $Prototype = ['field1', 'field2'];

	protected final function setField1Property($value) {
		return 'The mutated via setter value is: ' . $value;
	}

	protected final function getField2Property($value) {
		return 'The mutated via getter value is: ' . $value;
	}
}
```

Let's test it:

```
$Struct = new MyStruct(1,2);

echo $Struct->field1;
echo $Struct->field2;

//> The mutated via setter value is: 1
//> The mutated via getter value is: 2
```

The next example just illustrates the difference between setters and getters.

```
$Data = $Struct->toArray();

echo $Data['field1'];
echo $Data['field2'];

//> The mutated via setter value is: 1
//> 2
```

### Default values

[](#default-values)

The default values could be set via constants.

```
use \Able\Struct;

class MyParentStruct extends AStruct {

	protected static array $Prototype = ['field1', 'field2'];

	protected const defaultField1Value = "default value for field1";
	protected const defaultField2Value = "default value for field2";
}
```

### Inheritance

[](#inheritance)

The inheritance level isn't limited. All fields defined at parent classes will also be accessible at child classes.

```
use \Able\Struct;

class MyParentStruct extends AStruct {

	protected static array $Prototype = ['field1', 'field2'];
}

class MyChildStruct extends MyParentStruct {

	protected static array $Prototype = ['field3'];
}
```

It perfectly works:

```
$Struct = new MyChildStruct(1,2,3);

echo $Struct->field1;
echo $Struct->field2;
echo $Struct->field3;

//> 1
//> 2
//> 3
```

### Advanced

[](#advanced)

To retrieve all structure keys:

```
$Struct->keys();
```

To retrieve all structure values:

```
$Struct->values();
```

To copy all data into an array:

```
$Struct->toArray();
```

To get fields count:

```
$Struct->count();
```

To clean all fields and restore its default values:

```
$Struct->flush();
```

IDEs support
------------

[](#ides-support)

If you use a PHPDoc-friendly IDE you can gain additional advantages by using the syntax below:

```
use \Able\Struct;

/**
 * @property int field1
 * @property string field2
 */
class MyStruct extends AStruct {

	protected static array $Prototype = ['field1', 'field2'];
}
```

License
-------

[](#license)

This package is released under the [MIT license](https://github.com/phpable/struct/blob/master/LICENSE).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Total

2

Last Release

1818d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/713792f971f1f5ac1719a94df2e9340e44e09b01ae8bd2987ca9b5a3a177a485?d=identicon)[able](/maintainers/able)

---

Top Contributors

[![hacpaka](https://avatars.githubusercontent.com/u/8544673?v=4)](https://github.com/hacpaka "hacpaka (18 commits)")

---

Tags

Structuresstructphpable

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/able-struct/health.svg)](https://phpackages.com/packages/able-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)
