Skip to content

Dot access for array/object access #60794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tacman opened this issue Jun 15, 2025 · 0 comments
Open

Dot access for array/object access #60794

tacman opened this issue Jun 15, 2025 · 0 comments

Comments

@tacman
Copy link
Contributor

tacman commented Jun 15, 2025

Description

I like the new JSON Path component.

But when I already have an object, I sometime want an easy way to access the elements. I've been using https://packagist.org/packages/adbario/php-dot-notation but there are other that provide the same functionality.

Example

$composerData = json_decode(file_get_contents('composer.json'));
$data = new Dot($composerData);

// old way, still works
foreach ($data['config']['allow-plugins'] as $plugin) {}

// with dot
foreach ($data['config.allow-plugins'] as $plugin) {}

It feels like JsonPath is pretty close to offering this. Perhaps there could be a way to implement an ArrayAccess interface so that

$jsonPath = ... (get the jsonpath object from a json string or an existing object/array).
$jsonPath['home.owner.name.first'].

Of course, at this point it's not a JsonPath, so maybe a new component could be introduce.

A bit of brainstorming here, I'm still wrapping my head around all the cool features related to DTO, and wanted to bring this up as a way to access nested values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant