Commit bb8e3ed 1 parent 80045df commit bb8e3ed Copy full SHA for bb8e3ed
File tree 1 file changed +33
-0
lines changed
components/property_access
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,39 @@ see `Enable other Features`_.
309
309
310
310
echo $person->getWouter(); // array(...)
311
311
312
+ Checking Property Paths
313
+ -----------------------
314
+
315
+ .. versionadded :: 2.5
316
+ The methods
317
+ :method: `PropertyAccessor::isReadable<Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::isReadable> `
318
+ and
319
+ :method: `PropertyAccessor::isWritable<Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::isWritable> `
320
+ methods were added in Symfony 2.5.
321
+
322
+ When you want to check whether :method: `PropertyAccessor::getValue<Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::getValue> `
323
+ can safely be called without actually calling that method, you can use
324
+ :method: `PropertyAccessor::isReadable<Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::isReadable> `
325
+ instead::
326
+
327
+ $person = new Person();
328
+
329
+ if ($accessor->isReadable($person, 'firstName') {
330
+ // ...
331
+ }
332
+
333
+ The same is possible for :method: `PropertyAccessor::setValue<Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::setValue> `:
334
+ Call the
335
+ :method: `PropertyAccessor::isWritable<Symfony\\ Component\\ PropertyAccess\\ PropertyAccessor::isWritable> `
336
+ method to find out whether a property path can be updated. In the third
337
+ argument, you should pass the value that you want to write::
338
+
339
+ $person = new Person();
340
+
341
+ if ($accessor->isWritable($person, 'firstName', 'Wouter') {
342
+ // ...
343
+ }
344
+
312
345
Mixing Objects and Arrays
313
346
-------------------------
314
347
You can’t perform that action at this time.
0 commit comments