Download the PHP package setbased/helper-cast without Composer

On this page you can find all versions of the php package setbased/helper-cast. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package helper-cast

Cast

Social Legal Release Tests Code
Gitter License Latest Stable Version
Build Status
Code Coverage
Scrutinizer Code Quality

This package contains a strong typed utility class for safely testing and casting mixed values to bool, float, int, or string values.

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):

but gives the following output:

This package provides a strong typed utility class for safely testing and casting mixed typed values to Boolean, float, integer, or string values.

Manual

The class SetBased\Helper\Cast has the following methods for testing mixed values against primitive data types:

Method Null Value Return Type
isManBool returns false bool
isManFloat returns false bool
isManFiniteFloat returns false bool
isManInt returns false bool
isManString returns false bool
isOptBool returns true bool
isOptFloat returns true bool
isOptFiniteFloat returns true bool
isOptInt returns true bool
isOptString returns true bool

The class SetBased\Abc\Helper\Cast has the methods shown in the table below for casting mixed values to a primitive data type. When a value can not cast an exception will be thrown.

Method Null Value Return Type
toManBool throws an exception bool
toManFloat throws an exception float
toManFloatInclusive throws an exception float
toManInt throws an exception int
toManString throws an exception string
toOptBool returns null bool|null
toOptFloat returns null float|null
toOptFloatInclusive returns null float|null
toOptInt returns null int|null
toOptString returns null string|null

Remarks:

Sample

Code:

Output:

Finite Floats

A float can be finite (e.g. 3.14), infinite (i.e. INF or -INF), or not a number (i.e. NAN). The [is|to][Man|Opt]FiniteFloat methods will assist in establishing a value is a real floating point number.

Booleans

Only and only the following values are valid representations of boolean values:

Hence, only these values can be cast safely to booleans and vice versa.

Installing

References

License

This project is licensed under the MIT license.


All versions of helper-cast with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package setbased/helper-cast contains the following files

Loading the files please wait ....