SensitiveParameter クラス

(PHP 8 >= 8.2.0)

はじめに

このアトリビュートを使うと、スタックトレース中に現れた場合に、 値を削除すべき秘密の値としてパラメータをマークできます。

クラス概要

finalclassSensitiveParameter {
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