2017 © Pedro PelĂĄez
 

library assert

Provides runtime assertions

image

wikimedia/assert

Provides runtime assertions

  • Saturday, July 28, 2018
  • by mediawiki
  • Repository
  • 24 Watchers
  • 5 Stars
  • 215,149 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 6 Versions
  • 6 % Grown

The README.md

This package provides an alternative to PHP's assert() that allows for an simple and reliable way to check preconditions and postconditions in PHP code. It was proposed as a MediaWiki RFC, but is completely generic and can be used by any PHP program or library. It is published under the MIT license, see the COPYING file., (*1)

Usage

The Assert class provides several static methods for checking various kinds of assertions. The most common kind is to check the type of a parameter, typically in a constructor or a setter method:, (*2)

function setFoo( $foo ) {
    Assert::parameterType( 'integer', $foo, 'foo' );
    Assert::parameter( $foo > 0, 'foo', 'must be greater than 0' );
}

function __construct( $bar, array $bazz ) {
    Assert::parameterType( 'Me\MyApp\SomeClass', $bar );
    Assert::parameterElementType( 'int', $bazz );
}

Checking parameters, or other assertions such as pre- or postconditions, is not recommended for performance critical regions of the code, since evaluating expressions and calling the assertion functions costs time., (*3)

Rationale

The background of this proposal is the recurring discussions about whether PHP's assert() can and should be used in MediaWiki code. Two relevant threads: * Using PHP's assert in MediaWiki code * Is assert() allowed?, (*4)

The outcome appears to be that * assertions are generally a good way to improve code quality * but PHP's ''assert()'' is broken by design, (*5)

Following a suggestion by Tim Starling, this package provides an alternative to PHP's built in assert()., (*6)

The Versions

28/07 2018

dev-master

9999999-dev https://github.com/wikimedia/Assert

Provides runtime assertions

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Daniel Kinzler
by Thiemo MĂ€ttig
by Thiemo Kreuz

php assert qa precondition postcondition assertions

23/03 2016

dev-traversable

dev-traversable https://github.com/wmde/Assert

Provides runtime assertions

  Sources   Download

MIT

The Development Requires

by Daniel Kinzler

php assert qa precondition postcondition assertions

29/04 2015

v0.2.2

0.2.2.0 https://github.com/wmde/Assert

Provides runtime assertions

  Sources   Download

MIT

The Development Requires

by Daniel Kinzler

php assert qa precondition postcondition assertions

28/04 2015

v0.2.1

0.2.1.0 https://github.com/wmde/Assert

Provides runtime assertions

  Sources   Download

MIT

The Development Requires

by Daniel Kinzler

php assert qa precondition postcondition assertions

13/04 2015

v0.2.0

0.2.0.0 https://github.com/wmde/Assert

Provides runtime assertions

  Sources   Download

MIT

The Development Requires

by Daniel Kinzler

php assert qa precondition postcondition assertions

30/07 2014

v0.1.0

0.1.0.0 https://github.com/wmde/Assert

Provides runtime assertions

  Sources   Download

MIT

The Development Requires

by Daniel Kinzler

php assert qa precondition postcondition assertions