PHPackages                             devuri/dot-access - 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. devuri/dot-access

ActiveLibrary

devuri/dot-access
=================

A simple PHP library for accessing nested data using dot notation.

v0.3.1(2y ago)125.4k↓100%3MITPHPPHP ^7.4 || ^8.0CI passing

Since Jul 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/devuri/dot-access)[ Packagist](https://packagist.org/packages/devuri/dot-access)[ RSS](/packages/devuri-dot-access/feed)WikiDiscussions master Synced 1mo ago

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

DotAccess - Convenient Access to Nested Data Using Dot Notation
===============================================================

[](#dotaccess---convenient-access-to-nested-data-using-dot-notation)

The `DotAccess` class provides a user-friendly wrapper around the functionality of the `Dflydev\DotAccessData\Data` package, allowing easy access to nested data using dot notation in PHP.

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

[](#installation)

1. Ensure you have [Composer](https://getcomposer.org/) installed on your system.
2. Run the following command to install the package:

```
composer require devuri/dot-access
```

Getting Started
---------------

[](#getting-started)

1. Include the `DotAccess` class in your PHP script:

```
use Urisoft\DotAccess;
```

2. Create an instance of the `DotAccess` class and pass the nested data (array or object) to the constructor:

```
$data = [
    'user' => [
        'name' => 'John Doe',
        'email' => 'john.doe@example.com',
        'address' => [
            'city' => 'New York',
            'country' => 'USA',
        ],
    ],
];

$dotdata = new DotAccess($data);
```

Accessing Data
--------------

[](#accessing-data)

The `DotAccess` class provides the following methods to access the nested data using dot notation:

### Get the Value

[](#get-the-value)

Use the `get()` method to retrieve the value associated with a dot notation key:

```
$name = $dotdata->get('user.name');
$email = $dotdata->get('user.email');
$city = $dotdata->get('user.address.city');
```

### Set the Value

[](#set-the-value)

Use the `set()` method to set a value for a dot notation key:

```
$dotdata->set('user.age', 30);
```

### Checking for Key Existence

[](#checking-for-key-existence)

Use the `has()` method to check if a dot notation key exists in the data:

```
$emailExists = $dotdata->has('user.email');
```

### Removing a Key

[](#removing-a-key)

Use the `remove()` method to unset the value associated with a dot notation key:

```
$dotdata->remove('user.address.country');
```

Example
-------

[](#example)

```
$data = [
    'user' => [
        'name' => 'John Doe',
        'email' => 'john.doe@example.com',
        'address' => [
            'city' => 'New York',
            'country' => 'USA',
        ],
    ],
];

$dotdata = new DotAccess($data);

$name = $dotdata->get('user.name'); // Output: "John Doe"
$dotdata->set('user.age', 30);
$emailExists = $dotdata->has('user.email'); // Output: true
$dotdata->remove('user.address.country');

echo "Name: $name\n";
echo "Age: " . $dotdata->get('user.age') . "\n";
echo "Email exists: " . ($emailExists ? 'Yes' : 'No') . "\n";
```

Wrapper Function - DataKey:get()
--------------------------------

[](#wrapper-function---datakeyget)

In addition to the `DotAccess` class, we also provide a standalone wrapper function `DataKey` that simplifies accessing nested data using dot notation.

### Usage

[](#usage)

The `DataKey:get()` function allows you to quickly access nested data without having to create an instance of the `DotAccess` class. It takes three parameters:

1. The data array or object to access.
2. The dot notation key to access the data.
3. An optional default value to return if the key is not found.

Here's how you can use the `DataKey:get()` function:

```
$data = [
    'user' => [
        'name' => 'John Doe',
        'email' => 'john.doe@example.com',
        'address' => [
            'city' => 'New York',
            'country' => 'USA',
        ],
    ],
];

// Using the wrapper function
$name = DataKey:get($data, 'user.name');
$email = DataKey:get($data, 'user.email');
$city = DataKey:get($data, 'user.address.city');
$zipCode = DataKey:get($data, 'user.address.zip_code', 'N/A'); // Provide a default value if the key doesn't exist

echo "Name: $name\n";
echo "Email: $email\n";
echo "City: $city\n";
echo "Zip Code: $zipCode\n";
```

### When to Use `DataKey:get()` vs. `DotAccess`

[](#when-to-use-datakeyget-vs-dotaccess)

Both the `DataKey:get()` function and the `DotAccess` class serve the same purpose: accessing nested data using dot notation. The choice between them depends on your specific use case and coding preferences.

Use `DataKey:get()` when:

- You prefer a simple function call over creating an instance of the `DotAccess` class.
- You only need to access nested data at a few specific points in your code.
- You don't need to perform multiple operations (e.g., setting, checking, or removing keys).

Use `DotAccess` class when:

- You need to perform multiple operations on the same nested data within your code.
- You prefer an object-oriented approach for handling nested data.
- You need better encapsulation and separation of concerns in your code.

Both approaches provide a convenient and user-friendly way to work with nested data using dot notation. Choose the one that best fits your coding style and requirements.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Acknowledgments
---------------

[](#acknowledgments)

The `DotAccess` class is a simple wrapper around the `Dflydev\DotAccessData\Data` package, which provides the core functionality for accessing nested data using dot notation. Special thanks to the authors of the `Dflydev\DotAccessData` package for their excellent work.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~121 days

Total

3

Last Release

772d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8fd19f958b007ec6588d0a5ca2fe78e107edd652f286b836d36b5d1781d573a5?d=identicon)[devuri](/maintainers/devuri)

---

Top Contributors

[![devuri](https://avatars.githubusercontent.com/u/4777400?v=4)](https://github.com/devuri "devuri (18 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

dot-accessdot notationnested-data

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/devuri-dot-access/health.svg)

```
[![Health](https://phpackages.com/badges/devuri-dot-access/health.svg)](https://phpackages.com/packages/devuri-dot-access)
```

###  Alternatives

[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[jawira/case-converter

Convert strings between 13 naming conventions: Snake case, Camel case, Pascal case, Kebab case, Ada case, Train case, Cobol case, Macro case, Upper case, Lower case, Sentence case, Title case and Dot notation.

1746.9M79](/packages/jawira-case-converter)[selective/transformer

A strictly typed array transformer with dot-access, fluent interface and filters.

3817.8k1](/packages/selective-transformer)[pharaonic/php-dot-array

Access array data quickly/easily using dot-notation and asterisk.

1011.6k3](/packages/pharaonic-php-dot-array)[michaels/data-manager

Simple data manager for nested data, dot notation array access, extendability, and container interoperability.

121.9k2](/packages/michaels-data-manager)

PHPackages © 2026

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