PHPackages                             setbased/helper-cast - 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. setbased/helper-cast

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

setbased/helper-cast
====================

Safely cast mixed values to bool, float, int, or string

3.1.0(1y ago)154.6k—8.9%14MITPHPPHP &gt;=8.3CI failing

Since Feb 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SetBased/php-helper-cast)[ Packagist](https://packagist.org/packages/setbased/helper-cast)[ RSS](/packages/setbased-helper-cast/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (14)

Cast
====

[](#cast)

SocialLegalReleaseTests[![Gitter](https://camo.githubusercontent.com/a85934e99f3e13ba86c2283863d702ef5df6b128c3fb59ca4e505d276d494826/68747470733a2f2f6261646765732e6769747465722e696d2f53657442617365642f7068702d6162632e737667)](https://gitter.im/SetBased/php-abc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)[![License](https://camo.githubusercontent.com/7a57240980539fc2f7d4bc3039f95a19ea0d8456facf21f203507ecb0408a301/68747470733a2f2f706f7365722e707567782e6f72672f73657462617365642f68656c7065722d636173742f6c6963656e7365)](https://packagist.org/packages/setbased/helper-cast)[![Latest Stable Version](https://camo.githubusercontent.com/3f486100b45ff7201b11e233cd26d9d87cab8dff5cdb7a50ce9187e8eea45fad/68747470733a2f2f706f7365722e707567782e6f72672f73657462617365642f68656c7065722d636173742f762f737461626c65)](https://packagist.org/packages/setbased/helper-cast)
[![Build Status](https://github.com/SetBased/php-helper-cast/actions/workflows/unit.yml/badge.svg)](https://github.com/SetBased/php-helper-cast/actions/workflows/unit.yml)
[![Code Coverage](https://camo.githubusercontent.com/ced02b866032ceddf583c960ae24f577119b4981db4376699b78fdb923bde5ca/68747470733a2f2f636f6465636f762e696f2f67682f53657442617365642f7068702d68656c7065722d636173742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/SetBased/php-helper-cast)This package contains a strong typed utility class for safely testing and casting mixed values to bool, float, int, or string values.

Rationale
=========

[](#rationale)

What is the purpose of this package and why is it necessary? PHP is a great language, however is has some quirks. One of them is that PHP will convert any string to an integer even when strict type is set.

The following code will not cause any error or warning (tested with PHP 7.2.12):

```
