Skip to content

updated PropertyAccess docs for PR 30536 #11156

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
Apr 6, 2019
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions components/property_access.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,30 @@ getters, this means that you can do something like this::

This will produce: ``He is an author``

Accessing a non existing property path
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default a :class:`Symfony\\Component\\PropertyAccess\\Exception\\NoSuchPropertyException` is thrown if the property path passed to :method:`PropertyAccessor::getValue<Symfony\\Component\\PropertyAccess\\PropertyAccessor::getValue>`
does not exist.
You can change this behaviour using the :method:`Symfony\\Component\\PropertyAccess\\PropertyAccessorBuilder::disableExceptionOnInvalidPropertyPath`
method::

// ...
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
->disableExceptionOnInvalidPropertyPath()
->getPropertyAccessor();

class Person
{
public $name;
}

$person = new Person();

// instead of throwing an exception the following code returns null
$value = $propertyAccessor->getValue($person, 'birthday');


Magic ``__get()`` Method
~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
13 changes: 13 additions & 0 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Configuration

* `magic_call`_
* `throw_exception_on_invalid_index`_
* `throw_exception_on_invalid_property_path`_

* `property_info`_

Expand Down Expand Up @@ -1726,6 +1727,18 @@ throw_exception_on_invalid_index
When enabled, the ``property_accessor`` service throws an exception when you
try to access an invalid index of an array.

throw_exception_on_invalid_property_path
........................................

**type**: ``boolean`` **default**: ``true``

.. versionadded:: 4.3

The ``throw_exception_on_invalid_property_path`` option was introduced in Symfony 4.3.

When enabled, the ``property_accessor`` service throws an exception when you
try to access an invalid property path of an object.

property_info
~~~~~~~~~~~~~

Expand Down