PHPackages                             labrodev/php-mixed-converter - 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. labrodev/php-mixed-converter

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

labrodev/php-mixed-converter
============================

PHP utility class that provides methods to convert mixed values to strings, ints or floats

v1.0.0(1y ago)0125↓100%MITPHPPHP &gt;=8.1

Since Aug 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/labrodev/php-mixed-converter)[ Packagist](https://packagist.org/packages/labrodev/php-mixed-converter)[ Docs](https://github.com/labrodev/php-mixed-converter)[ RSS](/packages/labrodev-php-mixed-converter/feed)WikiDiscussions master Synced today

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

Description
===========

[](#description)

PhpMixedConvert is PHP utility class that provides methods to convert mixed values to strings, ints or floats.

Sometimes there is necessity in a code to ensure that our variable is string, int or float, especially strict types declaration is enabled in the class. On other hand, there is sometimes cases when the exact type is unknown. For example, it happens often in Laravel and probably could happen in any other project/code structure.

So this utility class has 3 static methods to just convert variable with mixed type to certain type depends on context.

P.S. We surely could detect such cases when to convert from mixed to exact type due static analysis (for example, wtih PHPStan).

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

[](#installation)

To install the package, run the following command in your Laravel project:

```
composer require labrodev/php-mixed-converter
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher

Configuration
-------------

[](#configuration)

After installing the package, no additional configuration is needed to start using utility.

Usage
-----

[](#usage)

To use the utility, use Utility class in your class and just call existed static methods from it:

```
