PHPackages                             jasny/dotkey - 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. jasny/dotkey

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

jasny/dotkey
============

Dot notation access for objects and arrays

v2.2.0(1y ago)15222.3k↓71.8%26MITPHPPHP &gt;=8.1.0CI failing

Since Aug 12Pushed 1y ago2 watchersCompare

[ Source](https://github.com/jasny/dotkey)[ Packagist](https://packagist.org/packages/jasny/dotkey)[ RSS](/packages/jasny-dotkey/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (6)

[![jasny-banner](https://user-images.githubusercontent.com/100821/62123924-4c501c80-b2c9-11e9-9677-2ebc21d9b713.png)](https://user-images.githubusercontent.com/100821/62123924-4c501c80-b2c9-11e9-9677-2ebc21d9b713.png)

DotKey
======

[](#dotkey)

[![PHP](https://github.com/jasny/dotkey/actions/workflows/php.yml/badge.svg)](https://github.com/jasny/dotkey/actions/workflows/php.yml)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/bbb25a3cf6c707b3671f8f9443fc5dd257f0fdbb871b88784349f55b1145a825/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f646f746b65792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jasny/dotkey/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/0919822f3727bb0cd602c1914b86def3d0ad40c4bb6c03097521059700ba4319/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f646f746b65792f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jasny/dotkey/?branch=master)[![Packagist Stable Version](https://camo.githubusercontent.com/1be599f5adf670f732210d80ca243fd0e8469b4858d9924bb17c426eb63d9692/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a61736e792f646f746b65792e737667)](https://packagist.org/packages/jasny/dotkey)[![Packagist License](https://camo.githubusercontent.com/399a8cf21c15c72f64991e7db53e33351b2162285d998cbc36b34a6310b8c70a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a61736e792f646f746b65792e737667)](https://packagist.org/packages/jasny/dotkey)

Dot notation access for objects and arrays.

Inspired by the [node.js Dotty](https://github.com/deoxxa/dotty) library.

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

[](#installation)

```
composer require jasny/dotkey

```

Usage
-----

[](#usage)

```
use Jasny\DotKey\DotKey;

$subject = [
  "a" => [
    "b" => [
      "x" => "y"
    ]
  ]
];

DotKey::on($subject)->exists("a.b.x");        // true
DotKey::on($subject)->exists("a.b.z");        // false
DotKey::on($subject)->exists("a.b.x.o");      // false

DotKey::on($subject)->get("a.b.x");           // "y"
DotKey::on($subject)->get("a.b");             // ["x" => "y"]
DotKey::on($subject)->get("a.b.z");           // null
DotKey::on($subject)->get("a.b.x.o");         // Throws ResolveException because a.b.x is a string

DotKey::on($subject)->set("a.b.q", "foo");    // $subject = ["a" => ["b" => ["x" => "y", "q" => "foo"]]]
DotKey::on($subject)->set("a.d", ['p' => 1]); // $subject = ["a" => ["b" => ["x" => "y"]], "d" => ["p" => 1]]
DotKey::on($subject)->set("a.c.x", "bar");    // Throws ResolveException because a.c doesn't exist
DotKey::on($subject)->set("a.b.x.o", "qux");  // Throws ResolveException because a.b.x is a string

DotKey::on($subject)->put("a.b.q", "foo");    // $subject = ["a" => ["b" => ["x" => "y", "q" => "foo"]]]
DotKey::on($subject)->put("a.c.x", "bar");    // $subject = ["a" => ["b" => ["x" => "y"]], "c" => ["x" => "bar"]]

DotKey::on($subject)->remove("a.b.x");        // $subject = ["a" => ["b" => []]]
DotKey::on($subject)->remove("a.c.z");        // $subject isn't modified
DotKey::on($subject)->remove("a.b.x.o");      // Throws ResolveException because a.b.x is a string
DotKey::on($subject)->remove("a.b");          // $subject = ["a" => []]

DotKey::on($subject)->update("a.b", fn($value) => array_map('strtoupper', $value)); // $subject = ["a" => ["b" => ["x" => "Y"]]]
```

The subject may be an array or object. If an object implements `ArrayAccess` it will be treated as array.

```
use Jasny\DotKey\DotKey;

$obj = (object)["a" => (object)["b" => (object)["x" => "y"]]];

DotKey::on($obj)->exists("a.b.x");
DotKey::on($obj)->set("a.b.q", "foo");
```

`exists()` will return `false` when trying access a private or static property. All other methods will throw a `ResolveException`.

### Copy

[](#copy)

By default, the target is modified in place. With the `onCopy()` factory method, a copy will be made instead.

```
use Jasny\DotKey\DotKey;

$source = ["a" => ["b" => ["x" => "y"]]];

DotKey::onCopy($source, $copy)->set("a.b.q", "foo");  // $copy = ["a" => ["b" => ["x" => "y", "q" => "foo"]]]
```

With `onCopy()`, objects will be cloned if they're modified.

```
use Jasny\DotKey\DotKey;

$source = (object)["f" => (object)["x" => "y"], "g" => (object)["x" => "z"]]]];

DotKey::onCopy($source, $copy)->set("f.q", "foo");

$copy === $source;       // false, source is cloned
$copy->f === $source->f; // false, `f` is cloned and modified
$copy->g === $source->g; // true, `g` is not cloned
```

### Delimiter

[](#delimiter)

The default delimiter is a dot, but any string can be used as delimiter. Leading and trailing delimiters are stripped.

```
use Jasny\DotKey\DotKey;

DotKey::on($subject)->exists('/a/b/x', '/');
DotKey::on($subject)->get("/a/b/x", '/');
DotKey::on($subject)->set("/a/b/q", "foo", '/');
DotKey::on($subject)->put("/a/b/q", "foo", '/');
DotKey::on($subject)->remove("/a/b/q", '/');

DotKey::on($subject)->exists('a::b::c', '::');
```

### Set vs Put

[](#set-vs-put)

- `set('a.b.c', 1)` requires `'a.b'` to exist and be an object or array. If that's not the case, a `ResolveException` is thrown.
- `put('a.b.c', 1)` will always result in `$result["a"]["b"]["c"] === 1`. If `'a.b'` doesn't exist, it will be created. If it already exists and isn't an array or object, it will be overwritten.

The structure `put()` creates is either an associative array or an `\stdClass` object, depending on the type of the subject. Passing `true` as fourth argument forces this to an array, while passing `false` forces it to create an object.

```
use Jasny\DotKey\DotKey;

$subject = ["a" => null];
$obj = (object)["a" => null];

DotKey::on($subject)->put("a.b.o", 1, '.');        // ["a" => ["b" => ["o" => 1]]]
DotKey::on($subject)->put("a.b.o", 1, '.', true);  // ["a" => ["b" => ["o" => 1]]]
DotKey::on($subject)->put("a.b.o", 1, '.', false); // ["a" => (object)["b" => (object)["o" => 1]]]

DotKey::on($obj)->put("a.b.o", 1, '.');            // (object)["a" => (object)["b" => (object)["o" => 1]]]
DotKey::on($obj)->put("a.b.o", 1, '.', true);      // (object)["a" => ["b" => ["o" => 1]]]
DotKey::on($obj)->put("a.b.o", 1, '.', false);     // (object)["a" => (object)["b" => (object)["o" => 1]]]
```

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 91.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 ~662 days

Recently: every ~772 days

Total

6

Last Release

644d ago

Major Versions

v1.0.2 → v2.0.02020-02-07

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v2.0.0PHP &gt;=7.4.0

v2.2.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3379a93d51305df325df9045e1a8b205d195e4e8c01312dff53a000ee79002eb?d=identicon)[jasny](/maintainers/jasny)

---

Top Contributors

[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (22 commits)")[![moesjarraf](https://avatars.githubusercontent.com/u/5793511?v=4)](https://github.com/moesjarraf "moesjarraf (1 commits)")[![svenstm](https://avatars.githubusercontent.com/u/1632578?v=4)](https://github.com/svenstm "svenstm (1 commits)")

---

Tags

jsonarrayobjectquery

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jasny-dotkey/health.svg)

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

###  Alternatives

[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k309.5M3.0k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.2k417.9M1.6k](/packages/nette-utils)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k11.7M152](/packages/cuyz-valinor)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4581.2M5](/packages/athari-yalinqo)[jbzoo/data

An extended version of the ArrayObject object for working with system settings or just for working with data arrays

891.6M23](/packages/jbzoo-data)[lukascivil/treewalker

TreeWalker is a simple and small Library that will help you to work faster with manipulation of structures in PHP

741.1M7](/packages/lukascivil-treewalker)

PHPackages © 2026

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