PHPackages                             ntzm/strict-casts - 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. ntzm/strict-casts

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

ntzm/strict-casts
=================

Strict type casting for super defensive PHP

1.2.0(7y ago)2072[3 issues](https://github.com/ntzm/strict-casts/issues)[1 PRs](https://github.com/ntzm/strict-casts/pulls)MITPHP

Since Jun 20Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ntzm/strict-casts)[ Packagist](https://packagist.org/packages/ntzm/strict-casts)[ RSS](/packages/ntzm-strict-casts/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

PHP Strict Casts
================

[](#php-strict-casts)

Strict type casting for super defensive PHP

Installation
------------

[](#installation)

```
$ composer require ntzm/strict-casts

```

Usage
-----

[](#usage)

This package provides the following strict casts:

- `stringToBool`
- `intToBool`
- `stringToInt`
- `stringToFloat`

And the following general casts, which work with any input, but use strict casts when they can:

- `toBool`
- `toInt`
- `toFloat`

All mentioned functions live under the namespace `StrictCasts`. This way, before using them, they have to be imported through the `use function` statement.

Why?
----

[](#why)

PHP's inbuilt type casting is not strict at all, and will take almost any type and turn it into another, no matter how valid the conversion is, for example:

```
(int) 'hello' === 0;
(int) '5 hello' === 5;
(int) 'hello 5' === 0;
(int) '123,456' === 123;
```

This is a source of a great number of bugs, headaches and crying.

By ensuring that the conversion is valid before conversion, we can ensure that the casting happens exactly as we would expect it to, or it will fail! For example:

```
use function StrictCasts\stringToInt;

stringToInt('123') === 123;
stringToInt('-123') === -123;

stringToInt('hello'); // throws exception
stringToInt('5 hello'); // throws exception
stringToInt('hello 5'); // throws exception
stringToInt('123,456'); // throws exception
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~0 days

Total

3

Last Release

2565d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/103460227?v=4)[natzim](/maintainers/natzim)[@natzim](https://github.com/natzim)

---

Top Contributors

[![ntzm](https://avatars.githubusercontent.com/u/3888578?v=4)](https://github.com/ntzm "ntzm (10 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ntzm-strict-casts/health.svg)

```
[![Health](https://phpackages.com/badges/ntzm-strict-casts/health.svg)](https://phpackages.com/packages/ntzm-strict-casts)
```

PHPackages © 2026

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