PHP code example of blackbonjour / stdlib

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

    

blackbonjour / stdlib example snippets


$string      = new StdString('My vehicle has %d wheels.');
$translation = StdString::format($string, 4);

echo $translation; // My vehicle has 4 wheels.

$format      = '"%s" means "%s".';
$translation = StdString::format($format, 'Привет', new StdString('Hello'));

echo $translation; // "Привет" means "Hello".

$string = new StdString('FooBar');

echo $string[4]; // a

var_dump(Assert::empty(null, 0, '', [])); // true
var_dump(Assert::empty(null, 1, 'FooBar', [])); // false

var_dump(Assert::notEmpty(123, 'FooBar', [123])); // true
var_dump(Assert::notEmpty(123, 'FooBar', [])); // false

$allowedTypes = [Assert::TYPE_INTEGER, Assert::TYPE_FLOAT];

var_dump(Assert::validate($types, 123, 456.7));

$hashMap = new HashMap;
$hashMap->put(new StdString('FooBar'), ['foo' => 'bar']);

var_dump($hashMap->key() instanceof StdString); // Returns `true`

$hashMap->put(new stdClass, new StdString('NotFooBar'));

foreach ($hashMap as $key => $value) {
    echo StdString::format('%s => %s' . PHP_EOL, gettype($key), gettype($value));
}

/*
 * Output:
 *
 * object => array
 * object => object
 */