Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PropertyAccessor->getValue disable exception #30536

Closed
@wuestkamp

Description

@wuestkamp

Description
I think it would be nice to have the possibility of disabling the exception that is thrown and just using a default/null value as return from ->getValue()?

Currently we can only disable the exception for invalid array indexes:
https://symfony.com/doc/current/components/property_access.html#reading-from-arrays

Example

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

$object = new Object(); // no methods
$value = $propertyAccessor->getValue($object, 'test');
// $value = null

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions