PHPackages                             wikimedia/assert - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. wikimedia/assert

ActiveLibrary[Testing &amp; Quality](/categories/testing)

wikimedia/assert
================

Provides runtime assertions

v0.5.1(4y ago)9958.1k↑17.8%18MITPHPPHP &gt;=7.2.9

Since Jul 30Pushed 1mo ago20 watchersCompare

[ Source](https://github.com/wikimedia/mediawiki-libs-Assert)[ Packagist](https://packagist.org/packages/wikimedia/assert)[ Docs](https://github.com/wikimedia/Assert)[ RSS](/packages/wikimedia-assert/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (10)Used By (8)

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](https://www.mediawiki.org/wiki/Requests_for_comment/Assert), 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.

Usage
-----

[](#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:

```
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.

Rationale
---------

[](#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](https://lists.wikimedia.org/hyperkitty/list/wikitech-l@lists.wikimedia.org/thread/QPIUK62DQTG7M5X6YFMSAAVFG3KWLTX2/)
- [Is assert() allowed?](https://lists.wikimedia.org/hyperkitty/list/wikitech-l@lists.wikimedia.org/thread/2VJZQCIADFDKGVTIVKDOTJISPVMNWJAQ/)

The outcome appears to be that

- assertions are generally a good way to improve code quality
- but PHP's ''assert()'' is broken by design

Following a [suggestion by Tim Starling](https://lists.wikimedia.org/hyperkitty/list/wikitech-l@lists.wikimedia.org/message/TMWLEOYMG42ASPYFEVTQKRSXK77W26CW/), this package provides an alternative to PHP's built in `assert()`.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance59

Moderate activity, may be stable

Popularity44

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor4

4 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~385 days

Recently: every ~606 days

Total

8

Last Release

1610d ago

PHP version history (3 changes)v0.3.0PHP &gt;=5.3.0

v0.4.0PHP &gt;=5.6.99

v0.5.0PHP &gt;=7.2.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

![](https://www.gravatar.com/avatar/f281fc1a5701e1e7002129e0198e12bff5c8ce049377bf1f75b022d588a5bd94?d=identicon)[legoktm](/maintainers/legoktm)

![](https://www.gravatar.com/avatar/48fe6db5961e3fbad563a1572db822d6a6ec79f607bf744c53098d970d79f890?d=identicon)[brightbyte](/maintainers/brightbyte)

---

Top Contributors

[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (16 commits)")[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (15 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (9 commits)")[![tgr](https://avatars.githubusercontent.com/u/145412?v=4)](https://github.com/tgr "tgr (9 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (8 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (6 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (4 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (3 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (3 commits)")[![mariushoch](https://avatars.githubusercontent.com/u/2446964?v=4)](https://github.com/mariushoch "mariushoch (3 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (2 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (2 commits)")[![ZabeMath](https://avatars.githubusercontent.com/u/35405030?v=4)](https://github.com/ZabeMath "ZabeMath (1 commits)")[![mainframe98](https://avatars.githubusercontent.com/u/14977407?v=4)](https://github.com/mainframe98 "mainframe98 (1 commits)")[![KleinMuci](https://avatars.githubusercontent.com/u/84108018?v=4)](https://github.com/KleinMuci "KleinMuci (1 commits)")[![cscott](https://avatars.githubusercontent.com/u/156080?v=4)](https://github.com/cscott "cscott (1 commits)")[![paladox](https://avatars.githubusercontent.com/u/5727000?v=4)](https://github.com/paladox "paladox (1 commits)")

---

Tags

phpassertassertionsqapreconditionpostcondition

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-assert/health.svg)

```
[![Health](https://phpackages.com/badges/wikimedia-assert/health.svg)](https://phpackages.com/packages/wikimedia-assert)
```

###  Alternatives

[yegor256/phprack

Light framework for automation of integration tests

254.7k](/packages/yegor256-phprack)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
