Skip to content
Search
Examples

Types

Description

Type validation checks if a value matches the expected type without throwing exceptions. The isValid() method returns true if the value conforms to the type, false otherwise. This is useful for conditional logic, filtering data, or performing pre-flight checks before processing.

Unlike assertions, validation never throws - it's designed for control flow decisions rather than enforcing contracts.


Validate boolean values. Returns true for native booleans and boolean-like strings/integers.

Documentation

Code

<?php

declare(strict_types=1);

use function Flow\Types\DSL\type_boolean;

require __DIR__ . '/vendor/autoload.php';

echo 'Is true valid? ' . (type_boolean()->isValid(true) ? 'yes' : 'no') . "\n";
echo 'Is false valid? ' . (type_boolean()->isValid(false) ? 'yes' : 'no') . "\n";
echo 'Is "yes" valid? ' . (type_boolean()->isValid('yes') ? 'yes' : 'no') . "\n";
echo 'Is 1 valid? ' . (type_boolean()->isValid(1) ? 'yes' : 'no') . "\n";
echo 'Is "true" valid? ' . (type_boolean()->isValid('true') ? 'yes' : 'no') . "\n";
Contributors

Built in the open.

Join us on GitHub
scroll back to top