src/includes/classes/Core/Utils/Serializer.php
public function checkSetType($value, string $expected_type)
    {
        switch ($expected_type) {
            case 'bool':
            case 'boolean':
                $expected_type = 'bool';
                if ($value === '0' || $value === '1') {
                    $value = (bool) $value;
                }
                break; // Stop here.

            case 'int':
            case 'integer':
            case 'long':
                $expected_type = 'int';
                if (is_numeric($value) && mb_strpos($value, '.') === false) {
                    $value = (int) $value;
                }
                break; // Stop here.

            case 'float':
            case 'double':
            case 'real':
                $expected_type = 'float';
                if (is_numeric($value)) {
                    $value = (float) $value;
                }
                break; // Stop here.

            case 'string':
            case 'array':
            case 'object':
            case 'null':
                break; // Stop here.

            default: // Catch invalid type checks here.
                throw $this->c::issue(sprintf('Unexpected type: `%1$s`.', $expected_type));
        }
        $is = 'is_'.$expected_type; // See: <http://php.net/manual/en/function.gettype.php>

        return $is($value) ? $value : null;
    }
public function checkSetType($value, string $expected_type)
    {
        switch ($expected_type) {
            case 'bool':
            case 'boolean':
                $expected_type = 'bool';
                if ($value === '0' || $value === '1') {
                    $value = (bool) $value;
                }
                break; // Stop here.

            case 'int':
            case 'integer':
            case 'long':
                $expected_type = 'int';
                if (is_numeric($value) && mb_strpos($value, '.') === false) {
                    $value = (int) $value;
                }
                break; // Stop here.

            case 'float':
            case 'double':
            case 'real':
                $expected_type = 'float';
                if (is_numeric($value)) {
                    $value = (float) $value;
                }
                break; // Stop here.

            case 'string':
            case 'array':
            case 'object':
            case 'null':
                break; // Stop here.

            default: // Catch invalid type checks here.
                throw $this->c::issue(sprintf('Unexpected type: `%1$s`.', $expected_type));
        }
        $is = 'is_'.$expected_type; // See: <http://php.net/manual/en/function.gettype.php>

        return $is($value) ? $value : null;
    }
Check/set expected type.

@since 150424 Serializer.

@param mixed  $value         Value.
@param string $expected_type Data type.

@return mixed|null The typified value; else `null`.