Download the PHP package improved/type without Composer

On this page you can find all versions of the php package improved/type. 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 type

improved PHP library

type handling

PHP Scrutinizer Code Quality Code Coverage Packagist Stable Version Packagist License

Library for type handling.

This library provides a set of consistent functions for PHP. You should always use these types rather than the ones provided by PHP natively.

Installation

composer require improved/type

types

Reference

type_is

bool type_is(mixed $var, string|string[] $type)

Return true if variable has the specified type.

As type you can specify any internal type, including callable and object, a class name or a resource type (eg stream resource).

Typed arrays or iteratators are not supported, as it would require looping through them.

A question mark can be added to a class to accept null, eg "?string" is similar to using ["string", "null"].

type_check

mixed type_check(mixed $var, string|string[] $type, Throwable $throwable = null)

Validate that a variable has a specific type. The same types cas in type_is() can be used.

Typed arrays or iteratators are not supported. Use iterable_check_type instead.

By default a TypeError is thrown. Optionally you can pass an exception instead.

The message may contain a %s, which is replaced by the type description of $var. It optionally may contain a second %s which is replaced by the description of the required type. Use sprintf positioning to use the required type first.

If the message or the exception or error contains a %, a new throwable of the same type is created with the filled out message.

The function returns $var if the type matches, so you can use it while setting a variable.

A question mark can be added to a class to accept null, eg "?string" is similar to using ["string", "null"].

type_cast

mixed type_cast(mixed $var, string $type, Throwable $throwable = null)

Check the variable has a specific type or can be casted to that type, otherwise throw a TypeError or exception.

This function is similar to type_check, with the difference that is will cast the value in some cases

from to
string int only numeric strings and < PHP_INT_MAX
string float only numeric strings
int bool only 0 or 1
int float
int string
float int if float < PHP_INT_MAX
float string
bool int
array object \ stdClass if array has no numeric keys
object string if only has __toString() method
object array \ iterable only stdClass objects
null any scalar
null array
null object \ stdClass

In contrary to type_is and type_check, only one type may be specified.

A question mark can be added to a class to accept null, eg ?string will try to cast everything to a string except null.

type_describe

string type_describe(mixed $var, bool $detailed = false)

Get the type of a variable in a descriptive way to using in an (error) message.

For scalar, null and array values, the result is the same a gettype. Except for floats which will return float rather than double.

Objects are have their class name, appended with object. For resources the resource type is returned, appended with resource.

The detailed option describes both the value an type. This is similar to what is used in the error messages of type_check and type_cast.


All versions of type with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
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 improved/type contains the following files

Loading the files please wait ....