Symfony PropertyAccess

Read and write nested object or array properties using a simple string notation

Library
Composer
vv8.1.4
2,814stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
72/100Good
Development Activity64
Maintenance68
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture85
Code Quality88
Innovation74
Learning Curve78

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 PropertyAccessor with getValue()/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 PropertyAccessorBuilder to configure magic-method support (MAGIC_GET, MAGIC_SET, MAGIC_CALL) and enable a reflection cache
  • PropertyPath and PropertyPathBuilder for programmatically constructing and inspecting property paths
  • Typed exceptions (NoSuchPropertyException, NoSuchIndexException, InvalidTypeException, UninitializedPropertyException) for precise error handling
  • Optional integration with symfony/property-info for 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 ArrayAccess structures
  • 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search