Skip to content

Commit 1b424f8

Browse files
[PropertyAccess] Allow to escape dots and squared brackets in property paths
1 parent aa033f6 commit 1b424f8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/property_access.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ You can also use multi dimensional arrays::
8181
var_dump($propertyAccessor->getValue($persons, '[0][first_name]')); // 'Wouter'
8282
var_dump($propertyAccessor->getValue($persons, '[1][first_name]')); // 'Ryan'
8383

84+
.. tip::
85+
86+
If the key of the array contains a dot ``.``, a left squared bracket ``[``
87+
or a right squared bracket ``]``, it is possible to escape these characters
88+
with a backslash. In the above example, if the array key becomes ``first.name``,
89+
accessing the value can be achieved like this::
90+
91+
var_dump($propertyAccessor->getValue($persons, '[0][first\.name]')); // 'Wouter'
92+
var_dump($propertyAccessor->getValue($persons, '[1][first\.name]')); // 'Ryan'
93+
94+
.. versionadded:: 6.3
95+
96+
Escaping dots and squared brackets in a property path was introduced in Symfony 6.3.
97+
8498
Reading from Objects
8599
--------------------
86100

0 commit comments

Comments
 (0)