Download the PHP package edgaralexanderfr/php-types without Composer

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

PHP Types 🐘

View last release

PHP 8.3.0

Composer

PHP Types is a small library/framework aimed to improve and encourage strong typing across your project's codebase, consisting of basic array-types, useful data structures and more, that are not natively available by the language itself.

Table of contents 📖
  1. Requirements
  2. Installation
  3. Usage
    • 3.1 Primitive types
      • 3.1.1 Extending PHP primitive types
      • 3.1.2 ObjectType
    • 3.2 Primitive arrays
      • 3.2.2 BoolArray
      • 3.2.3 IntArray
      • 3.2.4 FloatArray
      • 3.2.5 StringArray
      • 3.2.6 ObjectArray
      • 3.2.7 Extra primitives arrays
    • 3.3 Standard types
      • 3.3.1 Standard Ints
      • 3.3.2 size_t
      • 3.3.3 Standard Ints Arrays
    • 3.4 Data structures
      • 3.4.1 HashSet
      • 3.4.2 IntHashSet
      • 3.4.3 StringHashSet
    • 3.5 Type errors
    • 3.6 hasAny() and isEmpty() methods
    • 3.7 The splice method
    • 3.8 The length property
    • 3.9 Defining custom types
      • 3.9.1 Defining custom arrays
      • 3.9.2 typedef()

Requirements

  1. PHP 8.3.0 or major
  2. Composer (optional)
  3. Have an initted Composer project (optional)

Installation

Install PHP Types via Composer:

or:

You can always download the library as .zip file, decompress it, store it somewhere in your target project and include the autoload.php file from the library's project root:

or:

You can download the packed .phar version of the library:

Usage

Primitive types

Extending PHP primitive types

PHP Types adds some cool extra types that you can play around with:

ObjectType

Primitive arrays

BoolArray

IntArray

FloatArray

StringArray

ObjectArray

Extra primitives arrays

Standard types

Standard Ints

Similarly to C, you can make use of the standard types (as you would by including the standard library) to specify and maintain integer values in certain ranges:

Note: keep in mind that these are only representative values and not actual low-level values where we're not saving space by storing specific bytes per integer.

size_t

We can also make use of the size_t data type to store large numbers based on sizes, lengths, etc:

Standard Ints Arrays

Data structures

HashSet

IntHashSet

StringHashSet

Type errors

In case you attempt to assign a value with a type different than an array's type, a TypeError is thrown:

hasAny() and isEmpty() methods

Arrays contain useful methods that help to determine whether if they're empty or contain at least 1 element in them:

The splice method

You can make use of the splice method from arrays the same way you'd use the array_splice function with normal arrays:

The splice method returns a multiple, consisting of the resultant array along with the extracted elements respectively.

The length property

Similarly to JavaScript/JS, you can make use of the length property to retrieve the count of total elements from a specific array:

Defining custom types

Defining custom arrays

To define custom arrays, you can create a new class that extends PHPTypes\ArrayObject and implements a typed constructor for such purpose, e.g:

typedef()

It is very common that we may need to define multiple arrays for multiple classes from our project/app, to do so, we can simplify the previous example with the usage of the typedef function, just like this:

Notice the usage of the @disregard and @var phpDoc tags to preserve the array treatment per User and recognize the acccess to all its properties and methods by our preferred text editor. We also conjunct the @var type definition with the ArrayObject type to recognize access to methods such as count, hasAny, isEmpty, splice, etc.

In case our User class resides inside a specific namespace, we can specify the full path to the namespace when calling typedef to define the new array inside the same namespace:

It is also recommended and a good practice to define custom types in a separate and dedicated file that can be accessed across our app, such as types.php


All versions of php-types with dependencies

PHP Build Version
Package Version
No informations.
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 edgaralexanderfr/php-types contains the following files

Loading the files please wait ....