jdwx/result
最新稳定版本:v1.0.4
Composer 安装命令:
composer require jdwx/result
包简介
A microscopic module for managing complex function call results.
README 文档
README
A microscopic PHP module for managing complex function call results.
Installation
You can require it directly with Composer:
composer require jdwx/result
Or download the source from GitHub: https://github.com/jdwx/result-php.git
Requirements
This module requires PHP 8.3 or later.
Usage
This module provides a simple way to report the results of a function call, including success/failure state and a message. It is
loosely inspired by the Result type in Rust.
Here is a basic usage example:
function ExampleFunction() : Result { return match( random_int( 0, 1 ) ) { 0 => Result::err( 'This is an error message.' ), 1 => Result::ok( 'This is an example message.', 42 ), }; } $result = ExampleFunction(); if( $result->isOK() ) { echo "Success ({$result}) with value: ", $result->unwrap(), "\n"; } else { echo "Error: {$result}\n"; # This will throw an exception $result->unwrap(); }
Stability
This module is considered stable and is used in production code.
History
This module was refactored out of a private repository in September 2025 when the same functionality was needed for an unrelated project. DRY!
统计信息
- 总下载量: 80
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-11