Skip to content

[PropertyAccess] Allow to escape dots and squared brackets in property paths #17924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions components/property_access.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ You can also use multi dimensional arrays::
var_dump($propertyAccessor->getValue($persons, '[0][first_name]')); // 'Wouter'
var_dump($propertyAccessor->getValue($persons, '[1][first_name]')); // 'Ryan'

.. tip::

If the key of the array contains a dot ``.`` or a left squared bracket ``[``,
it is possible to escape these characters with a backslash. In the above example,
if the array key ``first_name`` becomes ``first.name``, accessing the value can
be achieved like this::

var_dump($propertyAccessor->getValue($persons, '[0][first\.name]')); // 'Wouter'
var_dump($propertyAccessor->getValue($persons, '[1][first\.name]')); // 'Ryan'

Right squared brackets ``]`` don't need to be escaped.

.. versionadded:: 6.3

Escaping dots and left squared bracket in a property path was
introduced in Symfony 6.3.

Reading from Objects
--------------------

Expand Down