Skip to content
PHP Library that provides an implementation of userland types, powered with overloaded operators
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Fix incorrect name of packet Dec 11, 2019

Native matrix library

For a long time, PHP developers dreamed of being able to overload operators. And now, finally, this moment has come. Thanks to the PHP7.4 and the lisachenko/z-engine package, we can overload the operators of comparison, addition, multiplication, casting and much more!

This library is first ever userland PHP extension, that implements operator overloading for the Matrix class.

GitHub release Minimum PHP Version License

Pre-requisites and initialization

As this library depends on FFI, it requires PHP>=7.4 and FFI extension to be enabled. Also, current limitations of lisachenko/z-engine are also applied (x64, NTS)

To install this library, simply add it via composer:

composer require lisachenko/native-types

Now you can test it with following example:


use Native\Type\Matrix;

$first  = new Matrix([[10, 20, 30]]);
$second = new Matrix([[2, 4, 6]]);
$value  = $first * 2 + $second; // Matrix([[22, 44, 66]])

Supported features:

  • Matrices addition ($matrixA + $matrixB)
  • Matrices subtraction ($matrixA - $matrixB)
  • Matrices multiplication ($matrixA * $matrixB)
  • Matrices division ($matrixA / $matrixB)
  • Matrices division ($matrixA / $matrixB)
  • Matrices equality check ($matrixA == $matrixB)

For the future versions, I would like to implement native SSE/AVX assembly methods to improve the performance of calculation.

You can’t perform that action at this time.