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