PHP Conference Japan 2024

SensitiveParameter 屬性

(PHP 8 >= 8.2.0)

簡介

此屬性用於標記敏感參數,如果該參數存在於堆疊追蹤中,則應將其值遮蓋。

類別概要

final class SensitiveParameter {
/* 方法 */
public __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}

目錄

新增註記

使用者提供的註記

此頁面沒有使用者提供的註記。
To Top