# SensitiveParameter 注解

(PHP 8 >= 8.2.0)

## 简介

该注解用于标记敏感参数，如果出现在栈跟踪中，则应编辑其值。

## 类摘要

#[\Attribute]
final class SensitiveParameter {
/* 方法 */
public function __construct()
}

## 示例

    <?php

    function defaultBehavior(
        string $secret,
        string $normal
    ) {
        throw new Exception('Error!');
    }

    function sensitiveParametersWithAttribute(
        #[\SensitiveParameter]
        string $secret,
        string $normal
    ) {
        throw new Exception('Error!');
    }

    try {
        defaultBehavior('password', 'normal');
    } catch (Exception $e) {
        echo $e, PHP_EOL, PHP_EOL;
    }

    try {
        sensitiveParametersWithAttribute('password', 'normal');
    } catch (Exception $e) {
        echo $e, PHP_EOL, PHP_EOL;
    }

    ?>

上述示例在 PHP 8.2 中的输出类似于：

    Exception: Error! in example.php:7
    Stack trace:
    #0 example.php(19): defaultBehavior('password', 'normal')
    #1 {main}

    Exception: Error! in example.php:15
    Stack trace:
    #0 example.php(25): sensitiveParametersWithAttribute(Object(SensitiveParameterValue), 'normal')
    #1 {main}

## 参见

- 注解概览
- SensitiveParameterValue

## 目录

- SensitiveParameter::__construct — 构造新的 SensitiveParameter 属性实例

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open