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: 14 July 2026