You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -423,6 +423,54 @@ For example, `$data->getBlock("avocado.color")` returns a Block object with just
423
423
424
424
If you are going to access a non-valid key, an empty Block object is returned, so the `$data->getBlock("avocado.notexists")` returns a Block object with a length equal to 0.
425
425
426
+
### Missing key behavior
427
+
428
+
By default, accessing a non-existing key returns the provided default value **silently**.
429
+
430
+
You can configure three behaviors:
431
+
432
+
-**Silent** (default)
433
+
-**Warning** (non-fatal)
434
+
-**Exception**
435
+
436
+
437
+
#### Silent (default)
438
+
439
+
```php
440
+
$fruits = Block::make($fruitsArray);
441
+
// OR if you want to be more explicit: $fruits = Block::make($fruitsArray)->silentOnMissingKey();
442
+
443
+
$nothing = $fruits->get("a-missing-key", "DEFAULT VALUE"); // no warning, no exception
0 commit comments