File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,23 @@ method. This is done using the index notation that is used in PHP::
47
47
var_dump($propertyAccessor->getValue($person, '[first_name]')); // 'Wouter'
48
48
var_dump($propertyAccessor->getValue($person, '[age]')); // null
49
49
50
- As you can see, the method will return ``null `` if the index does not exists.
50
+ As you can see, the method will return ``null `` if the index does not exist.
51
+ But you can change this behavior with the
52
+ :method: `Symfony\\ Component\\ PropertyAccess\\ PropertyAccessorBuilder::enableExceptionOnInvalidIndex `
53
+ method::
54
+
55
+ // ...
56
+ $propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
57
+ ->enableExceptionOnInvalidIndex()
58
+ ->getPropertyAccessor();
59
+
60
+ $person = array(
61
+ 'first_name' => 'Wouter',
62
+ );
63
+
64
+ // instead of returning null, the code now throws an exception of type
65
+ // Symfony\Component\PropertyAccess\Exception\NoSuchIndexException
66
+ $value = $propertyAccessor->getValue($person, '[age]');
51
67
52
68
You can also use multi dimensional arrays::
53
69
You can’t perform that action at this time.
0 commit comments