Download the PHP package sj-i/typist without Composer

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

Typist

Minimum PHP version: 7.4.0 Packagist Packagist Downloads Github Actions Scrutinizer Code Quality Coverage Status Psalm coverage

Typist is a PHP library enforcing types of local variables.
It internally uses references to typed properties introduced in PHP 7.4.

Installation

Supported Versions

Usage

Basic Usage

Function interfaces are also available.

Nullable Types

or if you use PHP8, () can be omitted.

Function interfaces are available here too.

How it works

If you have ever read the RFC of Typed Properties, especially its section describing how it works with references, you might not have anything unclear.

So I try to put a bit of explanation here, with the readers who haven't read yet in mind.

References in PHP

Firstly, please see the following code.

Let's illustrate this code step by step, line by line.

First line

The first line can be illustrated as below.

php_reference_a

There is a variable named $a, and its value is 1.
That's all, very simple.

Second line

Then the code added the second line can be illustrated as below.

php_reference_ab

There are two variables named $a and $b.
They are just different names indicating the same data, which is 1 in this case. The relationship is not like "$a is a variable which contains 1, and $b is a pointer to $a". The functionality of the reference assignment operator =& is just creating another name of data.

Third line

One more reference assignment creates one more name. That's it. The final state can be illustrated as below.

php_reference_abc

So there can be a group that consists of multiple names indicating the same data. Any modifications via any names affect the result of reading via any other names in the group. The RFC of the Typed Properties calls them "reference set".

Typed Properties and References

Then, what happens if a reference set contains typed properties?

php_reference_abc_typed

Now it's about properties, so using $a or $b as an example is not appropriate anymore. This time I change the code as below.

It can be re-illustrated like this.

php_reference_typed_properties_ab_local_variable_c

So let's try to assign some values to $o->a.

It's easy and understandable results.

On the other hand, what about the example below?

And what about the example below?

If a reference set contains typed properties, all types in the set must be satisfied on its assignment. The interpreter actually checks each property type in that situation and throws \TypeError on error.

Here you have seen how a local variable can be a typed variable. A local variable within a reference set that contains typed properties is checked with its type.

You can get such local variables in two ways. One is reference assignment from typed properties, and another is reference assignment to typed properties.

Reference assignment from or to, returning reference or pass-by-reference

Reference assignment from typed properties can make typed local variables. Though I haven't chosen this way, I think this method is intuitive because what we are trying is virtually to extract the ability of type checking from typed properties.

I have seen two instances of this method.

The implementation of them could be summarized as below.

Both of them leak memory because each creation of typed variables put the reference to the typed property object in the global state. azjezz/typed provides methods to free the references manually.

There are two things I don't like about this method.

  1. Memory leak (or manual memory management)
  2. Forcing reference assignment in user code
    • using &= everywhere is somehow not pretty!
    • yeah, it's just my preference!!!!

As you can see from the code in this repository, problem 2 can be solved by using pass-by-reference.
Reference assignment from a typed property makes a reference set containing a typed property.
Reference assignment to a typed property also makes a reference set containing a typed property.

Then the return value can be used for something else.
By returning typed property object (this is called Enforcer in this library) and grab it by a local variable in the caller, problem 1 can be solved. The variable is only used to keep refcount of Enforcer, so an inconspicuous name like $_ would be good.

Use with psalm

Psalm emits warning when the type of a pass-by-reference variable is changed. So if you use this library, the type of local variable can also be checked statically. And more, $_ is ignored by UnusedVariable checks.


All versions of typist with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.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 sj-i/typist contains the following files

Loading the files please wait ....