PHP code example of minimalcode / php-java-optional

1. Go to this page and download the library: Download minimalcode/php-java-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/ */

    

minimalcode / php-java-optional example snippets


echo OptionalString::of('hello')->orElse('world');// echo 'hello' 

echo OptonalInt::ofNullable(null)->orElse(42);// echo 42

/**
 * @method Book get()
 * @method Book|null orElse($other)
 * @method Book orElseGet(callable $supplier)
 * @method Book orElseThrow(callable $exceptionSupplier)
 */
class OptionalBook extends AbstractOptional
{
    /**
     * @inheritdoc
     */
    protected function supports($value)
    {
        return $value instanceof Book;
    }
}

$book = new Book()
$optBook = OptionalBook::of($book);