From d53e11e3b29255ce379d9a50bf92d83b87e5c436 Mon Sep 17 00:00:00 2001 From: Kim Wuestkamp Date: Thu, 14 Mar 2019 12:38:43 +0100 Subject: [PATCH] updated PropertyAccess docs for PR 30536 --- components/property_access.rst | 24 ++++++++++++++++++++++++ reference/configuration/framework.rst | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/components/property_access.rst b/components/property_access.rst index 2e23043e562..c05f6cbfcc1 100644 --- a/components/property_access.rst +++ b/components/property_access.rst @@ -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` +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 ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index a01018268ae..bef9ff8ed9a 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -107,6 +107,7 @@ Configuration * `magic_call`_ * `throw_exception_on_invalid_index`_ + * `throw_exception_on_invalid_property_path`_ * `property_info`_ @@ -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 ~~~~~~~~~~~~~ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy