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.
Dict class to enforce consistency across configuration, request payloads, and dynamic attributes (e.g., user metadata). Reduces ambiguity in key access and improves maintainability.Dict instances with built-in merging, defaults, and validation. Aligns with Laravel’s config() but adds explicit intent (e.g., dict->get('key', default)).get()/set() operations.Dict methods like merge(), update(), or filter().Collection classes for simple key-value operations.Adopt if:
isset()/?? patterns, no defaults).Collection for simple key-value operations (lower memory/CPU overhead).dict->set('key', $value) vs. $array['key'] = $value).OptionsResolver).Look elsewhere if:
Collection or Illuminate\Support\Enumerable.spatie/array-to-object or league/arrayobjects.Config facade) that handles merging/validation natively."This package standardizes how we handle associative data in PHP—replacing raw arrays with a structured Dict class. For example, instead of scattered isset() checks or ?? operators, we’d use dict->get('key', default), which reduces bugs and improves code readability. It’s especially valuable for configuration management and dynamic data stores, where consistency saves development time and reduces technical debt. With no dependencies and minimal overhead, it’s a low-risk way to modernize our data handling without disrupting existing workflows."
*"php-standard-library/dict provides a thin, Laravel-compatible wrapper for arrays with key benefits:
get(), set(), and has() with defaults eliminate isset() spaghetti.dict->merge($overrides)).foreach and collection-style loops.Ideal for:
Tradeoffs:
Collection—this is for simple key-value needs.Proposal: Pilot it in one module (e.g., config management) to measure readability gains before rolling out broadly. Start with new features to avoid legacy code friction."*
*"Why use Dict instead of arrays?
dict->get('key', default) vs. $array['key'] ?? default.dict->merge($newData) instead of manual loops.Example:
// Before (raw array)
$config = config('app');
$theme = $config['theme'] ?? 'light';
// After (Dict)
$dict = new Dict(config('app'));
$theme = $dict->get('theme', 'light');
When to avoid:
Collection instead).Next steps:
How can I help you explore Laravel packages today?