Content · Web Development · PHP

PHP SensitiveParameterValue::getValue() Method: Usage and Examples

Retrieves a sensitive value wrapped by the PHP #[SensitiveParameter] mechanism. Revealing the value defeats the protection if it is logged; return it only to trusted application code.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

Retrieves a sensitive value wrapped by the PHP #[SensitiveParameter] mechanism.

The examples focus on the operation itself, including the important distinction: SensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value.

What It Does


Use the examples below to observe the behavior on a small dataset before extending it to application code.

Syntax and Return Value


SensitiveParameterValue::getValue(): mixed

The displayed signature describes the API or identifies any correction or optional dependency. When a parameter is optional, supply it only when the task requires it.

Declared return type: mixed. Read the behavior notes for important cases such as empty collections and destructive iteration.

Example 1: Basic Use


getValue deliberately unwraps sensitive data. Only forward it to trusted operations; never echo or log the secret itself.

<?php
$secret = new SensitiveParameterValue('token-abc');
$trustedFunction = static fn(string $token): int => strlen($token);
$length = $trustedFunction($secret->getValue());
echo "validated secret length: " . $length;

Output from a successful local PHP 8.4 run:

validated secret length: 9

Example 2: Checking Behavior


getValue deliberately unwraps sensitive data. Only forward it to trusted operations; never echo or log the secret itself.

<?php
$secret = new SensitiveParameterValue('key-123');
$trustedFunction = static fn(string $token): int => strlen($token);
$length = $trustedFunction($secret->getValue());
echo "validated secret length: " . $length;

Output from a successful local PHP 8.4 run:

validated secret length: 7

Example 3: Practical Example


getValue deliberately unwraps sensitive data. Only forward it to trusted operations; never echo or log the secret itself.

<?php
$secret = new SensitiveParameterValue('private-value');
$trustedFunction = static fn(string $token): int => strlen($token);
$length = $trustedFunction($secret->getValue());
echo "validated secret length: " . $length;

Output from a successful local PHP 8.4 run:

validated secret length: 13

Important Behavior and Edge Cases


Revealing the value defeats the protection if it is logged; return it only to trusted application code.

Comparison with Related Approaches


ApproachDifference
SensitiveParameterValue::getValueRetrieves a sensitive value wrapped by the PHP #[SensitiveParameter] mechanism.
Related API or alternativeSensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value.

Common Beginner Mistakes


MistakeCorrect approach
Ignoring the operation-specific limitsRevealing the value defeats the protection if it is logged; return it only to trusted application code.
Confusing it with a related APISensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value.

Key Takeaways


  • Retrieves a sensitive value wrapped by the PHP #[SensitiveParameter] mechanism.
  • Revealing the value defeats the protection if it is logged; return it only to trusted application code.
  • SensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value.

Use SensitiveParameterValue::getValue when its documented behavior matches the problem. Test the relevant edge cases in your own runtime before deploying it.

Share this resourceSend this page to someone who may find it useful.