mathiasgrimm/arraypath
Convenient array manipulation for PHP, especially multidimensional arrays. Safely get, set, check existence, add or remove values using simple “a/b/c” paths, avoiding undefined index notices. Optional class alias (A) for cleaner calls and IDE autocomplete.
isset() checks and nested array access, reducing cognitive load and improving readability. Ideal for teams working with deeply nested data structures (e.g., API responses, configuration files, or form submissions).A::get(), A::set(), etc.) instead of ad-hoc solutions.$request->all()).data_get()/data_set() (which lack exists() and remove() operations).isset() checks (e.g., A::exists($data, 'user.address.city')).A::set($config, 'logging.level', 'debug')).isset() chains or array_key_exists() checks.A::get() hints) and static analysis tools (e.g., PHPStorm, Psalm) for productivity.exists() checks—Laravel’s data_get() lacks this feature, and custom implementations are error-prone.get()/set() operations—Laravel’s built-in data_get()/data_set() (or Arr:: helpers) may suffice, though they lack exists() and remove().spatie/array-to-object or modern alternatives if long-term support is critical.null for missing keys, which may not align with strict null checks or modern PHP practices.get/set/exists/remove. Packages like spatie/array or native PHP functions may be better suited.Arr:: helpers or custom methods may be more flexible."ArrayPath is a lightweight, battle-tested tool that helps our PHP teams write cleaner, more maintainable code for nested data—like API responses, configurations, or form submissions. By replacing verbose isset() chains with simple path syntax (e.g., A::get($data, 'user/profile/name')), we can reduce bugs, accelerate development, and enforce consistency across the codebase. This package is used in production by [X] teams and integrates seamlessly with Laravel. We’re proposing a 1-hour spike to evaluate its adoption in [Module Y], with a goal of cutting 20–30% of array-handling boilerplate. The risk is low—it’s a drop-in replacement with minimal overhead—and the payoff is immediate productivity gains for our backend team."
Key Outcomes:
E_NOTICE errors and edge cases from missing keys.*"ArrayPath solves a common pain point: dealing with nested arrays in PHP without writing ugly isset() chains. Here’s why it’s worth adopting:
Pros:
$name = isset($data['user']['profile']['name']) ? $data['user']['profile']['name'] : null;
with this:
$name = A::get($data, 'user/profile/name');
E_NOTICE errors or manual null checks.get(), set(), exists(), and remove() operations—more than Laravel’s data_get().A) enables autocompletion and static analysis.Tradeoffs:
How to Start:
composer.json and register the alias in a service provider.isset() chain in a high-traffic module (e.g., a form handler or API parser).Alternatives:
data_get()/data_set() (lacks exists() and remove()).null coalescing), but these don’t solve nested paths.Let’s prototype this in [Module Z] and compare it to our current approach. If it reduces boilerplate by even 10%, it’s worth adopting."*
*"ArrayPath simplifies array access, which could impact:
isset() checks mean tests are easier to write and debug.null or a default), reducing flaky tests.A::exists() for pre-checks, tests can focus on the happy path.Potential Risks:
A::get($data, 'invalid/path')) silently return null. Ensure your tests account for this by:
A::exists() for critical paths.A::get($data, 'path', 'default')).Recommendation:
A::exists().null unexpectedly)."*How can I help you explore Laravel packages today?