PHP 8.1.28 Released!

La classe SensitiveParameter

(PHP 8 >= 8.2.0)

Introduction

Cet attribut est utilisé pour indiquer qu'un paramètre est sensible et que sa valeur doit être expurgée s'il est présent dans une trace de pile.

Synopsis de la classe

final class SensitiveParameter {
/* Méthodes */
public __construct()
}

Exemples

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

?>

Résultat de l'exemple ci-dessus en PHP 8.2 est similaire à :

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}

Sommaire

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top