PHP Basics

TypeChecker

A generic data type checker.

This allows to set a list of allowed atomic data types and fully qualified class names. It also provides a method to check if a value's data type matches at least one of these types.

Tags
author

Sebastian Meyer sebastian.meyer@opencultureconsulting.com

Table of Contents

Methods

getAllowedTypes()  : array<string|int, string>
Get allowed data types.
hasAllowedType()  : bool
Check if a value's data type is allowed.
isAllowedType()  : bool
Check if a data type is allowed.
setAllowedTypes()  : void
Set allowed data types.

Methods

getAllowedTypes()

Get allowed data types.

public getAllowedTypes() : array<string|int, string>
APIYes
Return values
array<string|int, string>

The list of allowed data types

hasAllowedType()

Check if a value's data type is allowed.

public hasAllowedType(mixed $value) : bool
APIYes
Parameters
$value : mixed

The value to check

Return values
bool

Whether the value's data type is allowed

isAllowedType()

Check if a data type is allowed.

public isAllowedType(string $type) : bool
APIYes
Parameters
$type : string

The type to check

Return values
bool

Whether the data type is allowed

setAllowedTypes()

Set allowed data types.

public setAllowedTypes([array<string|int, string> $allowedTypes = [] ]) : void
APIYes
Parameters
$allowedTypes : array<string|int, string> = []

Allowed data types

Tags
throws
InvalidArgumentException

if any value of $allowedTypes is not a string


        
On this page

Search results