PHP code example of mll-lab / php-utils

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

    

mll-lab / php-utils example snippets


use MLL\Utils\SafeCast;

// Safe integer casting
SafeCast::toInt(42);           // 42
SafeCast::toInt('42');         // 42
SafeCast::toInt('hello');      // throws InvalidArgumentException
SafeCast::tryInt('hello');     // null

// Safe float casting
SafeCast::toFloat(3.14);       // 3.14
SafeCast::toFloat('3.14');     // 3.14
SafeCast::toFloat('abc');      // throws InvalidArgumentException
SafeCast::tryFloat('abc');     // null

// Safe string casting
SafeCast::toString(42);        // '42'
SafeCast::toString(null);      // ''
SafeCast::tryString([1, 2]);   // null

// Safe boolean casting
SafeCast::toBool(true);        // true
SafeCast::toBool(1);           // true
SafeCast::toBool('0');         // false
SafeCast::toBool('true');      // throws InvalidArgumentException
SafeCast::tryBool('true');     // null

use MLL\Holidays\BavarianHolidays;

BavarianHolidays::$loadUserDefinedHolidays = static function (int $year): array {
    switch ($year) {
        case 2019:
            return ['22.03' => 'Day of the Tentacle'];
        default:
            return [];
    }
};
diff
vendor/mll-lab/php-utils/extension.neon
+- vendor/mll-lab/php-utils/rules.neon