php-standard-library/dict
Utility functions for working with PHP associative arrays (“dicts”): create, map, filter, and transform collections while preserving keys. Lightweight helpers from PHP Standard Library for cleaner, safer array manipulation.
config/, app/) and attribute-based workflows (e.g., Eloquent models, API responses).isset($array['key']) ?? $default → dict->get('key', $default)).collect()) with a stricter, dictionary-focused API.Arrayable or Jsonable interfaces).isset checks) may not justify adoption for high-throughput systems.Dict as a singleton for global use).Arrayable methods), the package may lag behind.config('app.*') with a Dict instance).Dict, legacy code uses arrays).Dict to JSON for API responses (may need custom Jsonable implementation).config() calls with a Dict instance (e.g., config('app') → new Dict(config('app'))).Dict to normalize request data (e.g., Dict::fromArray($request->all())).Dict trait for dynamic attributes (e.g., user->attributes->dict()).Dict to arrays/JSON via custom accessors.Illuminate\Support\Collection via adapters.Dict in new features (e.g., config bags, request payloads).// Before
$config = config('app');
$theme = $config['theme'] ?? 'light';
// After
$dict = new Dict(config('app'));
$theme = $dict->get('theme', 'light');
Dict instances for all dependencies.config() calls with Dict-wrapped config.Dict for dynamic attributes.Arrayable/Jsonable, but can implement interfaces manually.Dict as a singleton or per-request).Illuminate\Http\Request to return Dict).ArrayAccess or Doctrine’s collections.Dict::fromCollection($collection)).| Priority | Component | Effort | Risk | Notes |
|---|---|---|---|---|
| 1 | Configuration | Low | Low | Replace config() with Dict wrappers. |
| 2 | Request handling | Medium | Medium | Normalize input data into Dict. |
| 3 | Eloquent models | Medium | High | Requires trait/mixin implementation. |
| 4 | API responses | Low | Low | Add toArray()/toJson() methods. |
| 5 | Service classes | High | Medium | Refactor internal state management. |
isset/?? noise: Cleaner code for safe key access.get()/set() calls make data flow clearer.Dict structures could complicate var dumps.UndefinedIndex errors.DictException for domain-specific errors.Dict is serialized properly).Dict safe for multi-process (not multi-thread).| Scenario | Impact | Mitigation |
|---|---|---|
| Circular references | Infinite loops in toArray() |
Add maxDepth parameter to serialization. |
| Type mismatches | Runtime errors in strict mode | Use PHPStan to enforce type hints. |
| Serialization issues | JSON/API failures | Implement JsonSerializable. |
| Laravel version drift | API incompatibilities | Pin package version in composer.json. |
Dict vs. arrays in Laravel contexts (config, requests, models).Dict usage in PRs for new features.Dict (via static analysis).UndefinedIndex exceptions).How can I help you explore Laravel packages today?