PHP code example of granam / scalar

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

    

granam / scalar example snippets



namespace Granam\Scalar;

$scalar = new Scalar('foo');

// foo
echo $scalar;

$nullScalar = new Scalar(null);
// false
echo is_scalar($nullScalar->getValue());
// true
echo is_null($nullScalar->getValue());

// NULL
var_dump(ToScalar::toScalar(null);

try {
  Tools\ToScalar(null, true /* explicitly strict */);
} catch (Tools\Exceptions\WrongParameterType $scalarException) {
  // Something get wrong: Expected scalar or object with __toString method on strict mode, got NULL.
  die('Something get wrong: ' . $scalarException->getMessage());
}