El atributo SensitiveParameter

(PHP 8 >= 8.2.0)

Introducción

Este atributo se utiliza para marcar un parámetro que es sensible y cuya valor debe ser censurado si está presente en un rastro de pila.

Sinopsis de la Clase

#[\Attribute]
final class SensitiveParameter {
/* Métodos */
public function __construct()
}

Ejemplos

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

?>

Resultado del ejemplo anterior en PHP 8.2 es similar a:

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}

Tabla de contenidos