Symfony PropertyAccess
Read and write nested object or array properties using a simple string notation
Repository Health
Technical Analysis
The Symfony PropertyAccess component provides a unified API for reading and writing values on objects and arrays using a compact string path like person.address[0].street, instead of hand-written chains of getters, setters, and array-index checks. It resolves getters, setters, isX()/hasX() methods, public properties, magic __get/__set/__call, and array/ArrayAccess indices automatically, falling back gracefully across each strategy.
Because it powers property mapping deep inside the Symfony Form and Serializer components, it is battle-tested at massive scale and ships with an optional reflection-extractor cache (APCu or PSR-6) to keep repeated path resolution fast in production. It is a small, dependency-light library that any PHP project can adopt standalone, independent of the rest of the Symfony framework.
What You Get
- A
PropertyAccessorwithgetValue()/setValue()/isReadable()/isWritable()for dot-and-bracket property paths - Automatic resolution across getters, setters, adders/removers for collections, public properties, magic methods, and array indices
- A
PropertyAccessorBuilderto configure magic-method support (MAGIC_GET,MAGIC_SET,MAGIC_CALL) and enable a reflection cache PropertyPathandPropertyPathBuilderfor programmatically constructing and inspecting property paths- Typed exceptions (
NoSuchPropertyException,NoSuchIndexException,InvalidTypeException,UninitializedPropertyException) for precise error handling - Optional integration with
symfony/property-infofor read/write introspection and with PSR-6/APCu caches for performance
Common Use Cases
- Mapping HTTP form input onto nested domain objects without writing manual setter chains (used internally by Symfony Form)
- Generic data-mapper or serializer code that needs to get/set arbitrary object graphs by configurable path strings
- Building CMS or admin-panel field editors where the edited property is only known at runtime
- Validating or transforming deeply nested API payloads represented as arrays or
ArrayAccessstructures - Writing reusable library code that must work uniformly across plain objects, arrays, and collections implementing adders/removers
Under The Hood
Architecture — The library centers on PropertyAccessor, which parses a string path into a PropertyPath (via PropertyPathBuilder) and walks it segment by segment, calling an internal readPropertiesUntil()/write equivalent that tries reflection-based getter/setter/adder-remover resolution before falling back to magic methods or raw array access; each resolution attempt is guarded by typed exceptions (NoSuchPropertyException, NoSuchIndexException) so failures are precise rather than silent. Tech Stack — Pure PHP 8.4+ with no runtime dependencies beyond symfony/property-info for read/write introspection; optional integration with PSR-6 cache adapters or APCu lets the reflection metadata be cached across requests, and the component ships as a single flat namespace (Symfony\Component\PropertyAccess) with no build step. Code Quality — The Tests/ directory covers array access, ArrayObject variants, traversable collections, and adder/remover pluralization edge cases (e.g. TestPluralAdderRemoverAndSetter), reflecting the kind of exhaustive edge-case coverage expected from a component embedded in Symfony Form/Serializer; naming is consistent and every public method is documented with @author and behavior annotations. API Design — The public surface is deliberately small — getValue(), setValue(), isReadable(), isWritable() — with a builder (PropertyAccessorBuilder) for the handful of configuration knobs (magic method support, caching, exception throwing mode), making it easy to adopt with almost no boilerplate.
Used by 3 apps in this directory
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
Hyvor Relay
Devops · AI Development · Monitoring
Self-hosted, open-source email API that automates DNS, manages SMTP delivery, and provides deep observability — replacing SES, Mailgun, and SendGrid with infrastructure you fully own.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.