PHP code example of adrianschubek / optional
1. Go to this page and download the library: Download adrianschubek/optional library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adrianschubek / optional example snippets
// UserRepository::find(123) returns `null`
$balance = optional(UserRepository::find(123))->getBankAccount()->getBalance(); // Ok, no error. returns null
$balance = UserRepository::find(123)->getBankAccount()->getBalance(); // Error