Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd53e11e

Browse files
committed
updated PropertyAccess docs for PR 30536
1 parent67cc8ed commitd53e11e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎components/property_access.rst‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,30 @@ 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+
174+
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>`
175+
does not exist.
176+
You can change this behaviour using the:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessorBuilder::disableExceptionOnInvalidPropertyPath`
177+
method::
178+
179+
// ...
180+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
181+
->disableExceptionOnInvalidPropertyPath()
182+
->getPropertyAccessor();
183+
184+
class Person
185+
{
186+
public $name;
187+
}
188+
189+
$person = new Person();
190+
191+
// instead of throwing an exception the following code returns null
192+
$value = $propertyAccessor->getValue($person, 'birthday');
193+
194+
171195
Magic ``__get()`` Method
172196
~~~~~~~~~~~~~~~~~~~~~~~~
173197

‎reference/configuration/framework.rst‎

Lines changed: 13 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,18 @@ 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+
..versionadded::4.3
1736+
1737+
The ``throw_exception_on_invalid_property_path`` option was introduced in Symfony 4.3.
1738+
1739+
When enabled, the ``property_accessor`` service throws an exception when you
1740+
try to access an invalid property path of an object.
1741+
17291742
property_info
17301743
~~~~~~~~~~~~~
17311744

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp