PHPackages                             jzaleski/php-open\_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. jzaleski/php-open\_struct

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

jzaleski/php-open\_struct
=========================

A very flexible data-structure (inspired by Ruby's `ostruct` library)

0.0.1(10y ago)217MITPHPPHP &gt;= 5.4.0

Since Dec 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jzaleski/php-open_struct)[ Packagist](https://packagist.org/packages/jzaleski/php-open_struct)[ RSS](/packages/jzaleski-php-open-struct/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

Open\_Struct (PHP)
==================

[](#open_struct-php)

[![Build Status](https://camo.githubusercontent.com/97a37d34cf1c18f2de75c6a783a37148f3e090cbd2944a381d256afde44d6e72/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a7a616c65736b692f7068702d6f70656e5f7374727563742e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/jzaleski/php-open_struct)

A very flexible data-structure (inspired by Ruby's `ostruct` library)

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

[](#requirements)

This library requires PHP 5.4+

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

[](#installation)

You can easily install `Open_Struct` with the following command:

```
composer [global] require 'jzaleski/php-open_struct=*'

```

Usage
-----

[](#usage)

Creating a new \[empty\] instance:

```
$struct = new Open_Struct;
```

Creating a new instance from an array of attributes:

```
$struct = new Open_Struct(['foo' => 1, 'bar' => ['biz' => 2]]);
```

Dereferencing a top-level value:

```
$value = $struct->foo;
```

Getting a top-level value by index/key:

```
$value = $struct['foo'];
```

Dereferencing a nested value:

```
$nested_value = $struct->bar->biz;
```

Getting a nested value by index/key:

```
$nested_value = $struct['bar']['biz'];
```

Setting a top-level value:

```
$struct->foo = 2;
```

Setting a top-level value by index/key:

```
$struct['foo'] = 2;
```

Setting a nested value:

```
$struct->bar->biz = 3;
```

Setting a nested value by index/key:

```
$struct['bar']['biz'] = 3;
```

Unsetting a top-level value:

```
unset($struct->foo);
```

Unsetting a top-level value by index/key:

```
unset($struct['foo']);
```

Checking for the existence of a key:

```
isset($struct->foo);
```

Checking for the existence of a key by index/key:

```
isset($struct['foo']);
```

Setting a callback value (this is useful for scenarios where you want to derive or lazy-load a property):

```
$dao = new Data_Access_Object;

$struct = new Open_Struct(['something' => function() use ($dao) { return $dao->get_something(); }]);

$struct->something;
```

The `dirty` method will return `false` until initialization (the constructor) is complete:

```
$struct = new Open_Struct(['foo' => 1]);

$struct->dirty(); // returns: `false`
```

The `dirty` method will return `true`, after initialization (the constructor), when a value is set:

```
$struct = new Open_Struct;

$struct->foo = 1;

$struct->dirty(); // returns: `true`
```

The `dirty` method will return `false`, after initialization (the constructor), when a value is set back to its original state:

```
$struct = new Open_Struct(['foo' => 1]);

$struct->foo = 2;

$struct->dirty(); // returns: `true`

$struct->foo = 1;

$struct->dirty(); // returns: `false`
```

Getting the array of attributes:

```
$struct = new Open_Struct(['foo' => 1]);

$struct->foo = 2;

$struct->bar = 3;

$struct->attributes(); // returns: `['foo' => 2, 'bar' => 3]`
```

Getting the array of changed attributes:

```
$struct = new Open_Struct(['foo' => 1]);

$struct->bar = 2;

$struct->changed_attributes(); // returns: `['bar' => 2]`
```

The `changed_attributes` method will return an empty array. after initializaiton (the constructor), when a value is set back to its original state:

```
$struct = new Open_Struct(['foo' => 1]);

$struct->foo = 2;

$struct->changed_attributes(); // returns: `['foo' => 2]`

$struct->foo = 1;

$struct->changed_attributes(); // returns: `[]`
```

Contributing
------------

[](#contributing)

1. Fork it ( [http://github.com/jzaleski/php-open\_struct/fork](http://github.com/jzaleski/php-open_struct/fork) )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

3843d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2303800?v=4)[Jonathan W. Zaleski](/maintainers/jzaleski)[@jzaleski](https://github.com/jzaleski)

---

Top Contributors

[![jzaleski](https://avatars.githubusercontent.com/u/2303800?v=4)](https://github.com/jzaleski "jzaleski (17 commits)")

### Embed Badge

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

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

###  Alternatives

[bitbull/magento2-module-instagramwidget

Instagram stream for Magento2

259.0k](/packages/bitbull-magento2-module-instagramwidget)

PHPackages © 2026

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