Assert
Provides runtime assertions
|
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.
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:
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.
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:
The outcome appears to be that
Following a suggestion by Tim Starling, this package provides an alternative to PHP's built in assert()
.