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, plugin settings). This reduces ambiguity and bugs by replacing implicit array access ($array['key']) with explicit methods (dict->get('key')).Dict instances with built-in merging, defaults, and validation. Aligns with Laravel’s config() system but adds a programmatic layer for runtime overrides.isset() checks and nested array operations.dict->merge($overrides)).Collection patterns for iteration and chaining, easing adoption for teams familiar with Laravel’s fluent interfaces.OptionsResolver) when this package offers a lightweight, MIT-licensed solution with no dependencies.Dict implementations.Dict for app settings, feature flags, or third-party integrations.Dict for validation and transformation consistency.Adopt if:
isset()/?? patterns, nested array hell).Collection for simple key-value operations (lower overhead than full collections).dict->set('key', $value) vs. $array['key'] = $value).Look elsewhere if:
Collection or Illuminate\Support\Enumerable.spatie/array-to-object or league/arrayobjects.Config facade) that handles merging/validation natively.Arrayable, Jsonable) out of the box (this package requires manual implementation)."This package standardizes how we handle associative data in PHP—replacing raw arrays with a structured Dict class to reduce bugs and improve maintainability. For example, instead of scattered isset() checks or ?? operators, we’d use dict->get('key', default), cutting down on errors and making the codebase more predictable. It’s especially valuable for configuration management and dynamic attributes, where consistency saves development time. With no dependencies and minimal overhead, it’s a low-risk way to enforce best practices across the codebase."
*"php-standard-library/dict gives us a thin, Laravel-friendly wrapper for arrays with key benefits:
get(), set(), and has() with defaults replace isset() spaghetti.dict->merge($overrides)).foreach and collection-style loops.Top use cases:
config() calls with Dict instances for safer access.Dict for consistent validation/transformation.Dict for dynamic metadata.Dict to JSON/arrays with custom serialization.Tradeoffs:
Arrayable requires manual implementation).Proposal: Pilot in one module (e.g., config management) to measure readability gains before broader adoption. Start with opt-in usage in new features, then enforce via static analysis (PHPStan)."*
*"Tired of isset($array['key']) or ?? operators? Dict gives you:
// Before
$theme = $config['theme'] ?? 'light';
// After
$dict = new Dict($config);
$theme = $dict->get('theme', 'light');
Try it:
Dict::fromArray() to normalize input data.Dict trait for dynamic attributes.Need more? We can add Laravel-specific features (e.g., Arrayable support) as needed."*
How can I help you explore Laravel packages today?