PHPackages                             alexpts/php-typecast - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. alexpts/php-typecast

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alexpts/php-typecast
====================

Simple type cast request data

1.2.2(8y ago)1126MITPHPPHP ^7.1

Since Sep 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/alexpts/php-typecast)[ Packagist](https://packagist.org/packages/alexpts/php-typecast)[ Docs](https://github.com/alexpts/php-typecast)[ RSS](/packages/alexpts-php-typecast/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

PHP typecast
============

[](#php-typecast)

[![SensioLabsInsight](https://camo.githubusercontent.com/e8b144b5658d4cf245e2622510fb953557ce20027576aa460537c7f3397bb49e/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f36663832373633352d303239642d343462622d393438322d3234383762376434613339612f6269672e706e67)](https://insight.sensiolabs.com/projects/6f827635-029d-44bb-9482-2487b7d4a39a)

[![Build Status](https://camo.githubusercontent.com/35b5298030d7182321daee871e9531b1eb9e1810acbc61d8614a95c1da59db24/68747470733a2f2f7472617669732d63692e6f72672f616c65787074732f7068702d74797065636173742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/alexpts/php-typecast)[![Code Coverage](https://camo.githubusercontent.com/61333a7d51db89cccd2e4790efe7bf4d6ed044c1ad3898e8ec47b960fb4fe99e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c65787074732f7068702d74797065636173742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alexpts/php-typecast/?branch=master)[![Code Climate](https://camo.githubusercontent.com/06ed68bf9bf61a26d6fbd774b47fd8dbb9902ddcf256d4fe5bc71a0440b6fdab/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f616c65787074732f7068702d74797065636173742f6261646765732f6770612e737667)](https://codeclimate.com/github/alexpts/php-typecast)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7eabd879e662a9e85e4dc1142066efe7490b6d0c224b0c3a19d67762aeef0f80/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c65787074732f7068702d74797065636173742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alexpts/php-typecast/?branch=master)

Cast types

#### Install

[](#install)

`composer require alexpts/php-typecast`

#### Example

[](#example)

```
$body = [
    'title' => 'Some',
    'user' => [
        'name' => 'Alex'
        'age' => '29',
        'isAdmin' = 'false',
    ],
    'friendsIds' => ['1', '2', '3', 4],
    'date' => '11-12-2017',
    'date2' => '11-12-2017',
];

$caster = new TypeCast(new DeepArray);

// shot format
$data = $caster->cast($body, [
    'friendsIds' => ['array', ['each' => ['int']]],
    'title' => ['string'],
    'user' => ['array'],
    'user.name' => ['string'],
    'user.age' => ['int'],
    'user.isAdmin' => ['bool'],
    'date' => ['datetime'],
    'date2' => ['datetime', ['datetimeFormat' => ['Y-m-d']]], // full format
]);

/*
$data ==== [
    'title' => 'Some',
    'user' => [
        'name' => 'Alex'
        'age' => 29,
        'isAdmin' = false,
    ],
    'friendsIds' => [1, 2, 3, 4],
    'date' => new \DateTime('11-12-2017'),
    'date2' => '2017-12-11',
];
*/
```

#### Types:

[](#types)

##### string

[](#string)

Set type to string

##### bool

[](#bool)

Set type to boolean

##### int

[](#int)

Set type to int

##### array

[](#array)

Set type to array

##### float

[](#float)

Set type to float

##### object

[](#object)

Set type to float

##### null

[](#null)

Set type to null

##### numbers

[](#numbers)

Remove all not number symbols from string

##### each

[](#each)

Convert each array item to describe types (see example above)

##### datetime

[](#datetime)

Convert value to \\DateTime object with default timezone

##### datetimeFormat

[](#datetimeformat)

Convert \\DateTime object to string via format method

#### Custom convert type

[](#custom-convert-type)

You can add custom convert via method on TypeCast service

```
public function registerType(string $name, callable $handler): self
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~43 days

Total

5

Last Release

2989d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/31106536118e11bf9d0c9d7f467db5b534efa9c46ee76680b308f0c39d9a798c?d=identicon)[alexpts](/maintainers/alexpts)

---

Top Contributors

[![alexpts](https://avatars.githubusercontent.com/u/1306916?v=4)](https://github.com/alexpts "alexpts (12 commits)")

---

Tags

typetypescast

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alexpts-php-typecast/health.svg)

```
[![Health](https://phpackages.com/badges/alexpts-php-typecast/health.svg)](https://phpackages.com/packages/alexpts-php-typecast)
```

###  Alternatives

[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.3M129](/packages/webpatser-laravel-uuid)[jetbrains/phpstorm-stubs

PHP runtime &amp; extensions header files for PhpStorm

1.4k27.7M68](/packages/jetbrains-phpstorm-stubs)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49444.8M97](/packages/marc-mabe-php-enum)[symfony/type-info

Extracts PHP types information.

19751.9M114](/packages/symfony-type-info)[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
