PHPackages                             baagee/wtf-error - 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. baagee/wtf-error

ActiveLibrary

baagee/wtf-error
================

What the fuck! PHP error handler

v0.0.8(5y ago)161[1 issues](https://github.com/baagee/wtf-error/issues)1PHPPHP &gt;=7.1

Since Jan 1Pushed 5y agoCompare

[ Source](https://github.com/baagee/wtf-error)[ Packagist](https://packagist.org/packages/baagee/wtf-error)[ RSS](/packages/baagee-wtf-error/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)DependenciesVersions (9)Used By (1)

php错误异常展示类
==========

[](#php错误异常展示类)

默认的php异常/错误在页面上展示的很难看，通过set\_error\_handler和set\_exception\_handler可以捕获到错误和异常，按照自己喜欢的格式去输出或者隐藏

此类稍微封装了一下两种模式下的错误输出

具体使用：

`composer require baagee/wtf-error`

### 只需要在项目开头注册一下就行了

[](#只需要在项目开头注册一下就行了)

```
// 使用内置的错误处理展示
\BaAGee\Wtf\WtfError::register(new \BaAGee\Wtf\Handler\WtfHandler([
    'php_error_log_dir' => __DIR__ . '/log',//指定PHP错误log目录，为空 不记录
    // 是否是开发调试模式，会显示详细错误。生产环境下很不安全，建议为false
    'is_debug'          => true
]));
```

截图示例：

访问页面出错时：

[![示例](https://camo.githubusercontent.com/d23c9dc3d0209731cf37744c2e5488733660cc81759682566940ebb4811e1cea/68747470733a2f2f6d65696e762d313235363135313438342e636f732e61702d6265696a696e672e6d7971636c6f75642e636f6d2f7475636875616e672f2545342542432538312545342542382539412545352542452541452545342542462541312545362538382541412545352539422542455f36666464646161662d626261352d343138662d393538312d3335613933616661323531352e706e67)](https://camo.githubusercontent.com/d23c9dc3d0209731cf37744c2e5488733660cc81759682566940ebb4811e1cea/68747470733a2f2f6d65696e762d313235363135313438342e636f732e61702d6265696a696e672e6d7971636c6f75642e636f6d2f7475636875616e672f2545342542432538312545342542382539412545352542452541452545342542462541312545362538382541412545352539422542455f36666464646161662d626261352d343138662d393538312d3335613933616661323531352e706e67)

执行脚本出错时：

[![示例](https://camo.githubusercontent.com/93ec3e01c22a248b43f1bd60f6efc2e534f2c8577555fadc3c445f1ca1a45aa2/68747470733a2f2f6d65696e762d313235363135313438342e636f732e61702d6265696a696e672e6d7971636c6f75642e636f6d2f7475636875616e672f2545342542432538312545342542382539412545352542452541452545342542462541312545362538382541412545352539422542455f30306361623166382d646163622d346538352d626435352d3437356230313962666138322e706e67)](https://camo.githubusercontent.com/93ec3e01c22a248b43f1bd60f6efc2e534f2c8577555fadc3c445f1ca1a45aa2/68747470733a2f2f6d65696e762d313235363135313438342e636f732e61702d6265696a696e672e6d7971636c6f75642e636f6d2f7475636875616e672f2545342542432538312545342542382539412545352542452541452545342542462541312545362538382541412545352539422542455f30306361623166382d646163622d346538352d626435352d3437356230313962666138322e706e67)

### 使用自定义的错误处理

[](#使用自定义的错误处理)

```
/**
 * Class MyHandler
 */
class MyHandler extends \BaAGee\Wtf\Base\WtfHandlerAbstract
{
    /**
     * 自定义错误异常显示 必须实现
     * @param Throwable $t
     */
    public function throwableHandler(\Throwable $t)
    {
        header('content-type: application/json; charset=utf-8');
        // 输出json
        echo json_encode([
            'code'    => $t->getCode(),
            'message' => $t->getMessage(),
            'file'    => $t->getFile(),
            'line'    => $t->getLine(),
        ], JSON_UNESCAPED_UNICODE);
    }

    // 自定义写入Log 不是必须的，不用自己调用，定义好方法就会自动调用
    public function writePhpErrorLog(\Throwable $t)
    {
        file_put_contents('./log.log', $t->getMessage() . PHP_EOL, FILE_APPEND);
    }
}

\BaAGee\Wtf\WtfError::register(new MyHandler([
    'php_error_log_dir'    => __DIR__ . '/log',
    'is_debug'             => true,
    'product_error_hidden' => [E_WARNING, E_NOTICE, E_STRICT, E_DEPRECATED]
]));
```

输出结果:

```
{"code":0,"message":"Call to undefined function abc()","file":"\/Users\/baagee\/PhpstormProjects\/github\/wtf-error\/tests\/error.php","line":26}
```

### 详细见tests目录

[](#详细见tests目录)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~80 days

Total

8

Last Release

2122d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f3a062d2e991897f0a7441d4e002bb5be5217948bed92461ab08174f7134c1f?d=identicon)[baagee](/maintainers/baagee)

---

Top Contributors

[![baagee](https://avatars.githubusercontent.com/u/22995500?v=4)](https://github.com/baagee "baagee (4 commits)")

---

Tags

phperror

### Embed Badge

![Health badge](/badges/baagee-wtf-error/health.svg)

```
[![Health](https://phpackages.com/badges/baagee-wtf-error/health.svg)](https://phpackages.com/packages/baagee-wtf-error)
```

###  Alternatives

[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.4k](/packages/nunomaduro-collision)[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[thehocinesaad/laravel-error-ai

This package adds Ask AI button to the error page.

2214.4k](/packages/thehocinesaad-laravel-error-ai)

PHPackages © 2026

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