SensitiveParameter 类

(PHP 8 >= 8.2.0)

简介

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

类摘要

final class SensitiveParameter {
}

范例

<?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 
$ePHP_EOLPHP_EOL;
}

try {
    
sensitiveParametersWithAttribute('password''normal');
} catch (
Exception $e) {
    echo 
$ePHP_EOLPHP_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}

参见

注解概览