wikimedia/assert 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wikimedia/assert

最新稳定版本:v0.5.1

Composer 安装命令:

composer require wikimedia/assert

包简介

Provides runtime assertions

README 文档

README

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.

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

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

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

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

统计信息

  • 总下载量: 932.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 3
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 20
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固