PHPackages                             mfn/argument-validation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mfn/argument-validation

AbandonedArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

mfn/argument-validation
=======================

Validate arguments against a list of parameters

0.2(10y ago)0561MITPHPPHP &gt;=5.6

Since Nov 21Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mfn/php-argument-validation)[ Packagist](https://packagist.org/packages/mfn/argument-validation)[ Docs](http://github.com/mfn/php-argument-validation)[ RSS](/packages/mfn-argument-validation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (1)

Argument Validation library for PHP [ ![Travis Build Status](https://camo.githubusercontent.com/a501cd8c93a421c56717d53cd190e95d642cea7ce171f40d96366b71da80513b/68747470733a2f2f7472617669732d63692e6f72672f6d666e2f7068702d617267756d656e742d76616c69646174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mfn/php-argument-validation)
============================================================================================================================================================================================================================================================================================================================================================

[](#argument-validation-library-for-php--)

Homepage:

Blurb
=====

[](#blurb)

This library can be used to validate parameter definitions against a list of arguments.

The following PHP types are supported out of the box:

- `array`
- `any` Use for, well, any kind of type (aliased as `mixed`)
- `bool`|`boolean`
- `callable` Suports for the `['class', 'method']` syntax. For closures simply use the `\Closure` type hint
- `float`|`double`|`real`
- `int`|`integer`
- `number` (either `float` or `integer`)
- `numeric` (either `int` or `string`, if it represents a number)
- `object`
- `resource` Supports requiring a resource of a specific type with `resource`, e.g. for files you can use `resource`
- `string`
- any classname you provide

Features:

- Optional types are supported by prefixing with a question mark: `?@var`. This syntax was chosen to not break IDE support, e.g. PhpStorm et al.
- Classes `instanceof` validation is performed too, just write the full qualified class name, i.e. `Class` or `Namespace\Class`. See later note on fully qualified symbol names.
- Typed arrays, e.g. `array` or `string[]` as well as types for keys and values, i.e. `array`
- Support alternative types, e.g. `int|string`

The philosophy of the type checker is to strictly check the arguments, no type coercion magic is performed.

Note about classes and the leading backslash:

This library expects the docblock to have been "normalized", in a sense that all symbol names are fully qualified **without** a leading backslash. "Fully qualified" also means they're already resolved against the namespace and possibly use aliases. See  for a library which can to all this.

Requirements
============

[](#requirements)

PHP 5.6

Install
=======

[](#install)

Using composer: `composer.phar require mfn/argument-validation 0.1`

Example
=======

[](#example)

```
