PHP8 SensitiveParameter 類

2023-08-22 13:54 更新

(PHP 8 >= 8.2.0)

簡(jiǎn)介

該注解用于標(biāo)記敏感參數(shù),如果出現(xiàn)在棧跟蹤中,則應(yīng)編輯其值。

類摘要

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}

參見

  • 注解概覽
  • SensitiveParameterValue

目錄

  • SensitiveParameter::__construct — Construct a new SensitiveParameter attribute instance


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)