Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hide Sensitive Parameter

<?php

function secret($key, #[\SensitiveParameter] string $key2, $otherKey) {
    throw new Exception('');
}

$key = '123';
print secret(
    $key,                              // plain visible
    $key,                              // hidden by the method
    new SensitiveParameterValue($key)  // hidden by the caller
);

?>

PHP 8.2 introduces the #[SensitiveParameter] attribute to hide sensitive values from debug messages when used on function parameters. Additionally, the SensitiveParameterValue class allows you to mark data as sensitive at the caller level, ensuring it won’t appear in stack traces. To retrieve the original value when needed, simply call the $object->getValue() method.

See Also

PHP Features

Last updated: 09 November 2026