PHP code example of decodelabs / coercion
1. Go to this page and download the library: Download decodelabs/coercion 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/ */
decodelabs / coercion example snippets
use DecodeLabs\Coercion;
class MyClass {
protected string $string;
protected ?string $optionalString;
protected int $int;
public function __construct(array $params) {
$this->string = Coercion::toString($params['maybeString']);
$this->optionalString = Coercion::toStringOrNull($params['maybeString']);
$this->int = Coercion::toInt($params['maybeInt']);
}
}