2017 © Pedro Peláez

library logic-matrix

PHP Logical Matrix package



PHP Logical Matrix package

  • Thursday, July 5, 2018
  • by chippyash
  • Repository
  • 1 Watchers
  • 1 Stars
  • 75 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 50 % Grown



Quality Assurance

PHP 5.6 PHP 7 Build Status Test Coverage Code Climate, (*1)

See the Test Contract, (*2)

Please note that developer support for PHP5.4 & 5.5 was withdrawn at version 3.0.0 of this library. If you need support for PHP 5.4 or 5.5, please use a version >=2,<3, (*3)


This library aims to provide logic matrix functionality and builds on the chippyash/Matrix matrix data structure library:, (*4)

  • Everything has a test case
  • It's PHP 5.4+


The current library covers basic logical matrix manipulation., (*5)

If you want more, either suggest it, or better still, fork it and provide a pull request., (*6)

Check out chippyash/Matrix for Matrix data type support., (*7)

Check out chippyash/Math-Matrix for mathematical matrix operations, (*8)

Check out ZF4 Packages for more packages, (*9)

Operations supported

  • AndMatrix - return the result of two matrices ANDed
  • AndOperand - return matrix ANDed with a boolean operand
  • Not - return !matrix
  • OrMatrix - return the result of two matrices ORed
  • OrOperand - return matrix ORed with a boolean operand
  • XorMatrix - return the result of two matrices XORed
  • XorOperand - return matrix XORed with a boolean operand

The library is released under the GNU GPL V3 or later license, (*10)


Please see the chippyash/Matrix for underlying functionality. Anything you can do with a Matrix, you can do with a LogicalMatrix., (*11)

Coding Basics

A LogicalMatrix is a matrix for which all entries are a boolean value; true or false, (*12)

A shortcut for a single item matrix is to supply a single array, (*13)

    use chippyash\Logic\Matrix\LogicalMatrix;

    $mA = new LogicalMatrix([]);  //empty matrix
    $mA = new LogicalMatrix([[]]);  //empty matrix
    $mA = new LogicalMatrix([true]);  //single item matrix
    $mA = new LogicalMatrix([2, false]);  //1x2 matrix
    $mA = new LogicalMatrix([2, false],[true, 'foo']);  //2x2 matrix

N.B. A matrix construction values are converted to their boolean equivalent, so '' = false, 'foo' = true, 1 = true, 0 = false etc, according to normal PHP casting rules for boolean., (*14)

As with any TDD application, the tests tell you everything you need to know about the SUT. Read them! However for the short of temper amongst us, the salient points are:, (*15)

A Logical Matrix type is supplied, (*16)

  • LogicalMatrix(array $source, bool $normalizeDefault = false)

Logical Matrices have additional attributes over and above a Matrix

  • Attributes always return a boolean.
  • You can use the is() method of a Matrix to test for an attribute
  • Attributes implement the chippyash\Matrix\Interfaces\AttributeInterface
    //assuming $mA is a LogicalMatrix - this will return true
    if ($mA->is('Logical')) {}
    //is the same as, which can also be used on ordinary matrices
    $attr = new Logic\Matrix\Attribute\IsLogical();
    if ($attr($mA) {}

Logical Matrices have operations

  • Operations always returns a Logical Matrix
  • The original matrix is untouched
  • You can use the magic __invoke functionality
  • Operations implement the chippyash\Logical\Matrix\Interfaces\OperationInterface
    $mC = $mA("AndMatrix", $mB);
    //same as :
    $op = new Logic\Matrix\Operation\AndMatrix;
    $mC = $op($mA, $mB);

The following operations are supplied:, (*17)

  • AndMatrix - AND two matrices
  • AndOperand - AND matrix with boolean
  • Not - NOT a matrix
  • OrMatrix - OR two matrices
  • OrOperand - OR matrix with boolean
  • XorMatrix - XOR two matrices
  • XorOperand - XOR matrix with boolean

The magic invoke methods allow you to write in a functional way

        $fAnd = new AndMatrix();
        $fOr = new OrOperand();
        //($mA && $mB) || true
        return $fOr($fAnd($mA, $mB), true);

Changing the library

  1. fork it
  2. write the test
  3. amend it
  4. do a pull request

Found a bug you can't figure out?, (*18)

  1. fork it
  2. write the test
  3. do a pull request

NB. Make sure you rebase to HEAD before your pull request, (*19)


The library is hosted at Github. It is available at Packagist.org, (*20)


Install Composer, (*21)

For production

add, (*22)

    "chippyash/logical-matrix": "~2.0"

to your composer.json "requires" section, (*23)

For development

Clone this repo, and then run Composer in local repo root to pull in dependencies, (*24)

    git clone git@github.com:chippyash/Logical-matrix.git LogicMatrix
    cd LogicMatrix
    composer update

To run the tests:, (*25)

    cd LogicMatrix
    vendor/bin/phpunit -c test/phpunit.xml test/


This software library is released under the BSD 3 Clause license, (*26)

This software library is Copyright (c) 2014-2018, Ashley Kitson, UK, (*27)


V0... pre releases, (*28)

V1.0.0 Original release, (*29)

V1.0.5 Update for underlying library dependency, (*30)

V1.0.6 Update phpunit version, (*31)

V2.0.0 BC Break: change namespace from chippyash to Chippyash, (*32)

V2.0.1 Add link to packages, (*33)

V2.0.2 Verify PHP7 compatibility, (*34)

V2.0.3 Update build script, (*35)

V3.0.0 BC Break. Withdraw support for old PHP versions, (*36)

V3.1.0 Change of license from GPL V3 to BSD 3 Clause, (*37)

The Versions

05/07 2018


9999999-dev http://zf4.biz/packages?utm_source=packagist&utm_medium=web&utm_campaign=blinks&utm_content=logicmatrix

PHP Logical Matrix package

  Sources   Download

BSD-3-Clause GPL-3.0+

The Requires


The Development Requires

05/07 2018
06/01 2018
09/03 2016

2.0.0 http://the-matrix.github.io/packages

PHP Logical Matrix package

  Sources   Download


The Requires


The Development Requires

03/12 2014


PHP Logical Matrix package

  Sources   Download


The Requires


The Development Requires

13/08 2014


PHP Logical Matrix package

  Sources   Download


The Requires


The Development Requires