Skip to content

Commit 5c323fb

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

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/property_access.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ 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 ``.`` or a left squared bracket ``[``,
87+
it is possible to escape these characters with a backslash. In the above example,
88+
if the array key ``first_name`` becomes ``first.name``, accessing the value can
89+
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+
Right squared brackets ``]`` don't need to be escaped.
95+
96+
.. versionadded:: 6.3
97+
98+
Escaping dots and left squared bracket in a property path was
99+
introduced in Symfony 6.3.
100+
84101
Reading from Objects
85102
--------------------
86103

0 commit comments

Comments
 (0)