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 exact literal values. Returns true only for the specified exact value.

Documentation

Code

<?php

declare(strict_types=1);

use function Flow\Types\DSL\type_literal;

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

echo 'Is "active" valid for literal("active")? ' . (type_literal('active')->isValid('active') ? 'yes' : 'no') . "\n";
echo 'Is "inactive" valid for literal("active")? ' . (type_literal('active')->isValid('inactive') ? 'yes' : 'no') . "\n";
echo 'Is 42 valid for literal(42)? ' . (type_literal(42)->isValid(42) ? 'yes' : 'no') . "\n";
echo 'Is 43 valid for literal(42)? ' . (type_literal(42)->isValid(43) ? 'yes' : 'no') . "\n";
echo 'Is true valid for literal(true)? ' . (type_literal(true)->isValid(true) ? 'yes' : 'no') . "\n";
Contributors

Built in the open.

Join us on GitHub
scroll back to top