8000 updated PropertyAccess docs for PR 30536 · symfony/symfony-docs@84b9148 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84b9148

Browse files
committed
updated PropertyAccess docs for PR 30536
1 parent 67cc8ed commit 84b9148

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

components/property_access.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,29 @@ getters, this means that you can do something like this::
168168

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

171+
Accessing a non existing property path
172+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173+
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>`
174+
does not exist.
175+
You can change this behaviour using the :method:`Symfony\\Component\\PropertyAccess\\PropertyAccessorBuilder::disableExceptionOnInvalidPropertyPath`
176+
method::
177+
178+
// ...
179+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
180+
->disableExceptionOnInvalidPropertyPath()
181+
->getPropertyAccessor();
182+
183+
class Person
184+
{
185+
public $name;
186+
}
187+
188+
$person = new Person();
189+
190+
// instead of throwing an exception the following code returns a null value
191+
$value = $propertyAccessor->getValue($person, 'birthday');
192+
193+
171194
Magic ``__get()`` Method
172195
~~~~~~~~~~~~~~~~~~~~~~~~
173196

reference/configuration/framework.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Configuration
107107

108108
* `magic_call`_
109109
* `throw_exception_on_invalid_index`_
110+
* `throw_exception_on_invalid_property_path`_
110111

111112
* `property_info`_
112113

@@ -1726,6 +1727,14 @@ throw_exception_on_invalid_index
17261727
When enabled, the ``property_accessor`` service throws an exception when you
17271728
try to access an invalid index of an array.
17281729

1730+
throw_exception_on_invalid_property_path
1731+
........................................
1732+
1733+
**type**: ``boolean`` **default**: ``true``
1734+
1735+
When enabled, the ``property_accessor`` service throws an exception when you
1736+
try to access an invalid property path of an object.
1737+
17291738
property_info
17301739
~~~~~~~~~~~~~
17311740

0 commit comments

Comments
 (0)
0