PHPackages                             uuur86/strobj - 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. uuur86/strobj

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

uuur86/strobj
=============

This repository allows you to access objects via string.

v2.1.9(1y ago)32281[1 issues](https://github.com/uuur86/strobj/issues)[3 PRs](https://github.com/uuur86/strobj/pulls)1GPL-2.0-or-laterPHPPHP &gt;=7.2CI passing

Since Jun 29Pushed 2mo agoCompare

[ Source](https://github.com/uuur86/strobj)[ Packagist](https://packagist.org/packages/uuur86/strobj)[ GitHub Sponsors](https://github.com/codeplusdev)[ GitHub Sponsors](https://github.com/uuur86)[ RSS](/packages/uuur86-strobj/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (6)Versions (22)Used By (1)

PHP String Objects
==================

[](#php-string-objects)

[![Duplicated Lines (%)](https://camo.githubusercontent.com/30f9073e6770fda6974c3b373d210a0eee42a04e845ef1ab2bba67cda49f56ac/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d6475706c6963617465645f6c696e65735f64656e73697479)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)[![Maintainability Rating](https://camo.githubusercontent.com/bdab2e5f56ab2709fdc3f40d56c9735238de8c2da5ce9f9d08ee35ec96db37d7/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)[![Reliability Rating](https://camo.githubusercontent.com/7557779fa5cc726c004c03087bfc5f1d8114a6227f8d7e6bcb6ab09859f334ce/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)[![Security Rating](https://camo.githubusercontent.com/aa3bd2d36e84ebdd699b699094c43855195cb1b10fbfdf80a4ff3507a5b1a21c/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)[![Quality Gate Status](https://camo.githubusercontent.com/33ea68f062da6c5eb4bd852a4d4ef1517537a5102f557ad5b060f62d9f982840/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)[![Vulnerabilities](https://camo.githubusercontent.com/84393676731feaf707c93aff02e8ddc93dbf626417656032c1b586a8af211033/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d76756c6e65726162696c6974696573)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)[![Bugs](https://camo.githubusercontent.com/e15215696d9c81384130f1e0c4be86d0ad1838ea9bdd1a47f6faf638d0cb805f/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d62756773)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)[![Technical Debt](https://camo.githubusercontent.com/0d7e9828bf33398a8af62d29507406335f3786bb4ad2e3da92f0307392942e13/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d7575757238365f7374726f626a266d65747269633d7371616c655f696e646578)](https://sonarcloud.io/summary/new_code?id=uuur86_strobj)

PHP String Objects is a library that provides an easy and intuitive interface for working with PHP arrays and objects. With built-in validation and filtering, it makes it easier to access, manipulate and validate data, saving you time and frustration.

- Allows accessing objects via strings
- Allows checking if the values of objects are valid using pre-defined or custom validation rules
- Provides middleware functionality to set memory limits or other configurations
- Provides data filters to manipulate the values of objects
- Can be used to set or get values of objects and arrays in a simplified manner

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

[](#installation)

To install the library, run the following Composer command:

```
composer require uuur86/strobj
```

USAGE
-----

[](#usage)

To get started with PHP String Objects, include the following code at the top of your PHP file:

```
use StrObj\StringObjects;
require('vendor/autoload.php');
```

### BASIC USAGE

[](#basic-usage)

Here is an example of how to use PHP String Objects to access and manipulate data in a JSON string:

```
use StrObj\StringObjects;

require('vendor/autoload.php');

// String JSON data to be used
// or you can use an object/array
$persons = '{
    "persons": [
        {
            "name": "John Doe",
            "age": "twelve"
        },
        {
            "name": "Molly Doe",
            "age": "14"
        },
        {
            "name": "Lorem Doe",
            "age": "34"
        },
        {
            "name": "Ipsum Doe",
            "age": "21"
        }
    ]
}';

$test = StringObjects::instance(
    $persons,
    [
        'validation' => [
            'patterns' => [
                // Add a new pattern named 'age' which only accepts numbers
                'age' => '#^[0-9]+$#siu',
                // Add a new pattern named 'name' which only accepts letters and spaces
                'name' => '#^[a-zA-Z ]+$#siu',
            ],
            'rules' => [
                // first rule
                [
                    // path scope to be checked
                    'path' => 'persons/*/age',
                    // uses 'age' pattern
                    'pattern' => 'age',
                    // makes it required
                    'required' => true
                ],
                // second rule
                [
                    'path' => 'persons/*/name',
                    'pattern' => 'name',
                    'required' => true
                ],
            ],
        ],
        'middleware' => [
            // Sets memory limit to 3MB
            'memory_limit' => 1024 * 1024 * 3,
        ],
        // Output data filters
        'filters' => [
            // Filters all persons/*/age values
            'persons/*/age' => [
                // converts to integer
                'type' => 'int',
                // only accepts values greater than 10
                'callback' => function ($value) {
                    return $value > 10;
                }
            ],
            'persons/*/name' => [
                // converts to string (not necessary)
                'type' => 'string',
                // only accepts values which contains only letters and spaces
                'callback' => function ($value) {
                    return preg_match('#^[a-zA-Z ]+$#siu', $value);
                }
            ],
        ],
    ]
);

// False
var_dump($test->isValid('persons/0/age'));

// True
var_dump($test->isValid('persons/1/age'));

// False
var_dump($test->isValid('persons/*/age'));

// False
var_dump($test->isValid('persons'));

// Updates value of persons/0/name
$test->set('persons/0/name', 'John D.');

// Updates value of persons/0/age
$test->set('persons/0/age', 12);

// Adds a new person named "Neo Doe" with age 199
$test->set('persons/4/name', 'Neo Doe');
$test->set('persons/4/age', 199);

// Outputs "John D."
$test->get('persons/0/name');

// Outputs "12"
$test->get('persons/3/age');

// Outputs "Neo Doe"
$test->get('persons/4/name');

// Outputs "199"
$test->get('persons/4/age');

// Updates value of persons/4/age to "200"
$test->set('persons/4/age', 200);

// Outputs "200"
$test->get('persons/4/age');
```

DEVELOPMENT
-----------

[](#development)

### TESTS

[](#tests)

```
composer test
```

or

```
php vendor/bin/phpunit tests/TestScenarios
```

LICENSE
-------

[](#license)

GPL-2.0-or-later

AUTHOR
------

[](#author)

Uğur Biçer - @uuur86

CONTRIBUTING
------------

[](#contributing)

If you want to contribute to this project, you can send pull requests. We expect all contributors to follow our [Code of Conduct](CONTRIBUTING.md).

CONTACT
-------

[](#contact)

You can contact me via email:

BUGS
----

[](#bugs)

You can report bugs via github issues.

SECURITY
--------

[](#security)

If you find a security issue, please report it via email:

DONATE
------

[](#donate)

If you want to support me, you can donate via github sponsors:

SEE ALSO
--------

[](#see-also)

- [uuur86/wpoauth](https://github.com/uuur86/wpoauth) - Wordpress OAuth2 Client
- [@codeplusdev](https://github.com/codeplusdev) - Codeplus Development

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance57

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 98.8% 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 ~125 days

Total

16

Last Release

627d ago

Major Versions

v0.5.1 → v1.0.02021-12-07

v1.0.3 → v2.1.62023-02-15

PHP version history (2 changes)v0.1PHP &gt;=5.6.0

v1.0.0PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![uuur86](https://avatars.githubusercontent.com/u/17476001?v=4)](https://github.com/uuur86 "uuur86 (81 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

data-managementdeveloper-toolsmicrolibraryobject-data-analysisobject-managementobject-manipulationphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/uuur86-strobj/health.svg)

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

PHPackages © 2026

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